删除列车后可再次添加相同编号列车
This commit is contained in:
parent
01b734ff9c
commit
fee0bed151
|
@ -244,7 +244,11 @@ func addTrain(c *gin.Context) {
|
|||
WheelDiameter: req.WheelDiameter,
|
||||
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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
trainEndsB dto.ConfigTrainEnds, mapId int32) *state_proto.TrainState {
|
||||
trainEndsB dto.ConfigTrainEnds, mapId int32) *sys_error.BusinessError {
|
||||
allTrainMap := &vs.Memory.Status.TrainStateMap
|
||||
_, ok := allTrainMap.Load(status.Id)
|
||||
value, ok := allTrainMap.Load(status.Id)
|
||||
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
|
||||
|
@ -108,7 +111,7 @@ func AddTrainStateNew(vs *VerifySimulation, status *state_proto.TrainState, conf
|
|||
})
|
||||
// 将信息合并到当前设备状态中
|
||||
allTrainMap.Store(status.Id, status)
|
||||
return status
|
||||
return nil
|
||||
}
|
||||
|
||||
// 增加列车状态
|
||||
|
@ -345,12 +348,14 @@ func RemoveAllTrain(vs *VerifySimulation) {
|
|||
return
|
||||
}
|
||||
allTrainMap.Range(func(k any, t any) bool {
|
||||
train := t.(*state_proto.TrainState)
|
||||
err := removeTrain(vs, train.Id, train)
|
||||
if err != nil {
|
||||
slog.Error("列车id:", train.Id, "移除失败,原因:", err.Error())
|
||||
}
|
||||
allTrainMap.Store(train.Id, t)
|
||||
id := k.(string)
|
||||
RemoveTrainState(vs, id)
|
||||
//train := t.(*state_proto.TrainState)
|
||||
//err := removeTrain(vs, train.Id, train)
|
||||
//if err != nil {
|
||||
// slog.Error("列车id:", train.Id, "移除失败,原因:", err.Error())
|
||||
//}
|
||||
//allTrainMap.Store(train.Id, t)
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
@ -364,8 +369,7 @@ func removeTrain(vs *VerifySimulation, trainId string, train *state_proto.TrainS
|
|||
return err
|
||||
}
|
||||
train.Show = false
|
||||
fi.RemoveTrainFromWorld(vs.World, trainId)
|
||||
return nil
|
||||
return fi.RemoveTrainFromWorld(vs.World, trainId)
|
||||
}
|
||||
|
||||
// 删除列车状态
|
||||
|
|
Loading…
Reference in New Issue