【修改ID映射】
This commit is contained in:
parent
810e1e61e1
commit
0668c8381a
@ -239,7 +239,7 @@ func switchOperation(c *gin.Context) {
|
||||
simulation := checkDeviceDataAndReturn(req.SimulationId)
|
||||
zap.S().Info("传入状态参数", req)
|
||||
memory.ChangeTurnoutState(simulation, &state.SwitchState{
|
||||
Id: req.SwitchIndex,
|
||||
Id: req.DeviceId,
|
||||
Normal: req.TurnNormal,
|
||||
Reverse: req.TurnReverse,
|
||||
}, req.MapId)
|
||||
|
@ -166,7 +166,7 @@ func convert(info *dynamics.TrainInfo, sta *state.TrainState, simulation *memory
|
||||
zap.S().Debugf("原始消息:[%d-%d-%d]", info.Number, info.Link, info.LinkOffset)
|
||||
id, port, offset, runDirection, pointTo, kilometer := memory.QueryDeviceByCalcLink(simulation.Repo, strconv.Itoa(int(info.Link)), int64(info.LinkOffset), info.Up)
|
||||
zap.S().Debugf("转换后的消息:[%d-车头:%s-偏移:%d-上行:%v-是否ab:%v]", info.Number, id, offset, runDirection, pointTo)
|
||||
sta.HeadDeviceId = strconv.Itoa(int(simulation.GetComIdByIndex(id)))
|
||||
sta.HeadDeviceId = simulation.GetComIdByUid(id)
|
||||
sta.DevicePort = port
|
||||
sta.HeadOffset = offset
|
||||
sta.PointTo = pointTo
|
||||
|
@ -81,15 +81,11 @@ func QueryGiData[T proto.Message](mapId int32) T {
|
||||
|
||||
// 根据区段,道岔偏移量返回linkID和link相对偏移量
|
||||
func QueryEcsLinkByDeviceInfo(repo *repository.Repository, mapId int32, id string, devicePort string, offset int64, runDirection bool) (int32, int64, bool, bool, int64) {
|
||||
index, err := strconv.Atoi(id)
|
||||
if err != nil {
|
||||
panic(&dto.ErrorDto{Code: dto.ArgumentParseError, Message: "类型不匹配"})
|
||||
}
|
||||
if devicePort == "" {
|
||||
uid := QueryUidByMidAndIndex(mapId, int32(index), &graphicData.Section{})
|
||||
uid := QueryUidByMidAndComId(mapId, id, &graphicData.Section{})
|
||||
return sectionMapToEcsLink(repo, uid, offset, runDirection)
|
||||
} else {
|
||||
uid := QueryUidByMidAndIndex(mapId, int32(index), &graphicData.Turnout{})
|
||||
uid := QueryUidByMidAndComId(mapId, id, &graphicData.Turnout{})
|
||||
return turnoutMapToEcsLink(repo, uid, devicePort, offset, runDirection)
|
||||
}
|
||||
}
|
||||
|
@ -262,14 +262,3 @@ func QueryUidByMidAndComId(mapId int32, comId string, m interface{}) string {
|
||||
}
|
||||
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("地图【id:%d】不存在【comId:%s】缓存", mapId, comId)})
|
||||
}
|
||||
|
||||
// 根据地图Index获取UID
|
||||
func QueryUidByMidAndIndex(mapId int32, index int32, m interface{}) string {
|
||||
uidMap := QueryMapUidMapByType(mapId, m)
|
||||
for _, u := range uidMap {
|
||||
if u.Index == index {
|
||||
return u.Uid
|
||||
}
|
||||
}
|
||||
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("地图【id:%d】不存在【Index:%d】缓存", mapId, index)})
|
||||
}
|
||||
|
@ -1,22 +1,15 @@
|
||||
package memory
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"joylink.club/rtsssimulation/entities"
|
||||
|
||||
"joylink.club/bj-rtsts-server/ats/verify/protos/graphicData"
|
||||
"joylink.club/bj-rtsts-server/ats/verify/protos/state"
|
||||
"joylink.club/bj-rtsts-server/dto"
|
||||
)
|
||||
|
||||
// 道岔相关道岔操作方法
|
||||
func ChangeTurnoutState(simulation *VerifySimulation, status *state.SwitchState, mapId int32) {
|
||||
index, err := strconv.Atoi(status.Id)
|
||||
if err != nil {
|
||||
panic(&dto.ErrorDto{Code: dto.ArgumentParseError, Message: "参数转换出错"})
|
||||
}
|
||||
uid := QueryUidByMidAndIndex(mapId, int32(index), &graphicData.Turnout{})
|
||||
uid := QueryUidByMidAndComId(mapId, status.Id, &graphicData.Turnout{})
|
||||
if status.Normal {
|
||||
entities.TurnToNormal(simulation.WorldId, uid)
|
||||
} else if status.Reverse {
|
||||
@ -54,7 +47,7 @@ func GetMapAllTurnoutState(sim *VerifySimulation, mapId int32) []*state.SwitchSt
|
||||
continue
|
||||
}
|
||||
switchArr = append(switchArr, &state.SwitchState{
|
||||
Id: strconv.Itoa(int(u.Index)),
|
||||
Id: u.CommonId,
|
||||
Normal: p.Normal,
|
||||
Reverse: p.Reverse,
|
||||
Turning: p.Turning,
|
||||
|
@ -163,18 +163,6 @@ func (s *VerifySimulation) GetComIdByUid(uid string) string {
|
||||
return es[uid].CommonId
|
||||
}
|
||||
|
||||
// 获取仿真世界信息
|
||||
func (s *VerifySimulation) GetComIdByIndex(uid string) int32 {
|
||||
es := s.uidMap
|
||||
if es == nil {
|
||||
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: "无映射信息"})
|
||||
}
|
||||
if es[uid] == nil {
|
||||
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: "无【uid】映射信息"})
|
||||
}
|
||||
return es[uid].Index
|
||||
}
|
||||
|
||||
func buildProtoRepository(mapIds []int32) (*proto.Repository, error) {
|
||||
repo := &proto.Repository{}
|
||||
var exceptStationGiMapIds []int32
|
||||
|
@ -64,7 +64,7 @@ type RemoveTrainDto AddTrainRspDto
|
||||
type SwitchOperationReqDto struct {
|
||||
SimulationId string `form:"simulationId" json:"simulationId" binding:"required"`
|
||||
MapId int32 `json:"mapId" from:"mapId" binding:"required"`
|
||||
SwitchIndex string `form:"switchIndex" json:"switchIndex" binding:"required"`
|
||||
DeviceId string `form:"id" json:"id" binding:"required"`
|
||||
TurnNormal bool `form:"turnNormal" json:"turnNormal"`
|
||||
TurnReverse bool `form:"turnReverse" json:"turnReverse"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user