【修改获取道岔状态逻辑】

This commit is contained in:
weizhihong 2023-09-27 14:15:11 +08:00
parent e50a9f1699
commit 8e9d7ee28a
7 changed files with 42 additions and 24 deletions

View File

@ -239,7 +239,7 @@ func switchOperation(c *gin.Context) {
simulation := checkDeviceDataAndReturn(req.SimulationId)
zap.S().Info("传入状态参数", req)
memory.ChangeTurnoutState(simulation, &state.SwitchState{
Id: req.Id,
Id: req.SwitchIndex,
Normal: req.TurnNormal,
Reverse: req.TurnReverse,
}, req.MapId)

View File

@ -81,11 +81,15 @@ 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 := QueryUidByMidAndComId(mapId, id, &graphicData.Section{})
uid := QueryUidByMidAndIndex(mapId, int32(index), &graphicData.Section{})
return sectionMapToEcsLink(repo, uid, offset, runDirection)
} else {
uid := QueryUidByMidAndComId(mapId, id, &graphicData.Turnout{})
uid := QueryUidByMidAndIndex(mapId, int32(index), &graphicData.Turnout{})
return turnoutMapToEcsLink(repo, uid, devicePort, offset, runDirection)
}
}

View File

@ -249,3 +249,14 @@ 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)})
}

View File

@ -1,15 +1,22 @@
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) {
uid := QueryUidByMidAndComId(mapId, status.Id, &graphicData.Turnout{})
index, err := strconv.Atoi(status.Id)
if err != nil {
panic(&dto.ErrorDto{Code: dto.ArgumentParseError, Message: "参数转换出错"})
}
uid := QueryUidByMidAndIndex(mapId, int32(index), &graphicData.Turnout{})
if status.Normal {
entities.TurnToNormal(simulation.WorldId, uid)
} else if status.Reverse {
@ -19,19 +26,14 @@ func ChangeTurnoutState(simulation *VerifySimulation, status *state.SwitchState,
// 获取全部的道岔状态,动力学使用
func GetAllTurnoutState(sim *VerifySimulation) []*state.SwitchState {
turnoutList := sim.Repo.TurnoutList()
var switchArr []*state.SwitchState
turnoutList := sim.Repo.TurnoutList()
for _, o := range turnoutList {
p := entities.GetState(sim.WorldId, o.Id())
sendObj := &state.SwitchState{Id: sim.GetComIdByUid(o.Id())}
switch p {
case entities.D:
sendObj.Normal = true
case entities.F:
sendObj.Reverse = true
default:
if p == nil {
continue
}
switchArr = append(switchArr, sendObj)
switchArr = append(switchArr, &state.SwitchState{Id: sim.GetComIdByUid(o.Id()), Normal: p.Normal, Reverse: p.Reverse})
}
return switchArr
}
@ -43,16 +45,10 @@ func GetMapAllTurnoutState(sim *VerifySimulation, mapId int32) []*state.SwitchSt
var switchArr []*state.SwitchState
for _, u := range uidMap {
p := entities.GetState(sim.WorldId, u.Uid)
sendObj := &state.SwitchState{Id: u.CommonId}
switch p {
case entities.D:
sendObj.Normal = true
case entities.F:
sendObj.Reverse = true
default:
if p == nil {
continue
}
switchArr = append(switchArr, sendObj)
switchArr = append(switchArr, &state.SwitchState{Id: strconv.Itoa(int(u.Index)), Normal: p.Normal, Reverse: p.Reverse})
}
return switchArr
}

View File

@ -2,12 +2,13 @@ package memory
import (
"fmt"
"joylink.club/rtsssimulation/simulation/world"
"sort"
"strconv"
"strings"
"sync"
"joylink.club/rtsssimulation/simulation/world"
"joylink.club/bj-rtsts-server/ats/verify/protos/graphicData"
"joylink.club/bj-rtsts-server/ats/verify/protos/state"
"joylink.club/bj-rtsts-server/dto"
@ -211,6 +212,9 @@ func relateRelay(repo *proto.Repository, relayGi *graphicData.RelayCabinetGraphi
for _, group := range relationship.Combinationtypes {
var relayUIds []string
for _, relayId := range group.RefRelays {
if uidsMap.RelayIds[relayId] == nil {
continue
}
relayUIds = append(relayUIds, uidsMap.RelayIds[relayId].Uid)
}
turnout.RelayGroups = append(turnout.RelayGroups, &proto.RelayGroup{
@ -226,6 +230,9 @@ func relateRelay(repo *proto.Repository, relayGi *graphicData.RelayCabinetGraphi
for _, group := range relationship.Combinationtypes {
var relayUIds []string
for _, relayId := range group.RefRelays {
if uidsMap.RelayIds[relayId] == nil {
continue
}
relayUIds = append(relayUIds, uidsMap.RelayIds[relayId].Uid)
}
signal.RelayGroups = append(signal.RelayGroups, &proto.RelayGroup{

View File

@ -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"`
Id string `form:"id" json:"id" binding:"required"`
SwitchIndex string `form:"switchIndex" json:"switchIndex" binding:"required"`
TurnNormal bool `form:"turnNormal" json:"turnNormal"`
TurnReverse bool `form:"turnReverse" json:"turnReverse"`
}

@ -1 +1 @@
Subproject commit 5fec9755b06bdb566e77092063676883e0bb6344
Subproject commit 5833de36fbb1e153672aa1ddf049f7006eefca60