删除列车后可再次添加相同编号列车
This commit is contained in:
parent
01b734ff9c
commit
fee0bed151
@ -244,7 +244,11 @@ func addTrain(c *gin.Context) {
|
|||||||
WheelDiameter: req.WheelDiameter,
|
WheelDiameter: req.WheelDiameter,
|
||||||
Speed: req.TrainSpeed,
|
Speed: req.TrainSpeed,
|
||||||
}
|
}
|
||||||
memory.AddTrainStateNew(simulation, rsp, req.ConfigTrain, req.TrainEndsA, req.TrainEndsB, req.MapId)
|
var err *sys_error.BusinessError = memory.AddTrainStateNew(simulation,
|
||||||
|
rsp, req.ConfigTrain, req.TrainEndsA, req.TrainEndsB, req.MapId)
|
||||||
|
if err != nil {
|
||||||
|
panic(sys_error.New("添加列车失败", err))
|
||||||
|
}
|
||||||
c.JSON(http.StatusOK, &rsp)
|
c.JSON(http.StatusOK, &rsp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,11 +35,14 @@ func CreateMsgTrainConfig(trainId int, trainLen int64, configTrainData dto.Confi
|
|||||||
|
|
||||||
// 增加列车状态
|
// 增加列车状态
|
||||||
func AddTrainStateNew(vs *VerifySimulation, status *state_proto.TrainState, configTrainData dto.ConfigTrainData, trainEndsA dto.ConfigTrainEnds,
|
func AddTrainStateNew(vs *VerifySimulation, status *state_proto.TrainState, configTrainData dto.ConfigTrainData, trainEndsA dto.ConfigTrainEnds,
|
||||||
trainEndsB dto.ConfigTrainEnds, mapId int32) *state_proto.TrainState {
|
trainEndsB dto.ConfigTrainEnds, mapId int32) *sys_error.BusinessError {
|
||||||
allTrainMap := &vs.Memory.Status.TrainStateMap
|
allTrainMap := &vs.Memory.Status.TrainStateMap
|
||||||
_, ok := allTrainMap.Load(status.Id)
|
value, ok := allTrainMap.Load(status.Id)
|
||||||
if ok {
|
if ok {
|
||||||
panic(fmt.Sprintf("列车【%s】已存在", status.Id))
|
trainState := value.(*state_proto.TrainState)
|
||||||
|
if trainState.Show {
|
||||||
|
return sys_error.New(fmt.Sprintf("列车【%s】已存在", status.Id))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 显示状态
|
// 显示状态
|
||||||
status.Show = true
|
status.Show = true
|
||||||
@ -108,7 +111,7 @@ func AddTrainStateNew(vs *VerifySimulation, status *state_proto.TrainState, conf
|
|||||||
})
|
})
|
||||||
// 将信息合并到当前设备状态中
|
// 将信息合并到当前设备状态中
|
||||||
allTrainMap.Store(status.Id, status)
|
allTrainMap.Store(status.Id, status)
|
||||||
return status
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// 增加列车状态
|
// 增加列车状态
|
||||||
@ -345,12 +348,14 @@ func RemoveAllTrain(vs *VerifySimulation) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
allTrainMap.Range(func(k any, t any) bool {
|
allTrainMap.Range(func(k any, t any) bool {
|
||||||
train := t.(*state_proto.TrainState)
|
id := k.(string)
|
||||||
err := removeTrain(vs, train.Id, train)
|
RemoveTrainState(vs, id)
|
||||||
if err != nil {
|
//train := t.(*state_proto.TrainState)
|
||||||
slog.Error("列车id:", train.Id, "移除失败,原因:", err.Error())
|
//err := removeTrain(vs, train.Id, train)
|
||||||
}
|
//if err != nil {
|
||||||
allTrainMap.Store(train.Id, t)
|
// slog.Error("列车id:", train.Id, "移除失败,原因:", err.Error())
|
||||||
|
//}
|
||||||
|
//allTrainMap.Store(train.Id, t)
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -364,8 +369,7 @@ func removeTrain(vs *VerifySimulation, trainId string, train *state_proto.TrainS
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
train.Show = false
|
train.Show = false
|
||||||
fi.RemoveTrainFromWorld(vs.World, trainId)
|
return fi.RemoveTrainFromWorld(vs.World, trainId)
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除列车状态
|
// 删除列车状态
|
||||||
|
Loading…
Reference in New Issue
Block a user