diff --git a/ats/verify/simulation/wayside/memory/wayside_memory_train.go b/ats/verify/simulation/wayside/memory/wayside_memory_train.go index 87443e6..542e6b1 100644 --- a/ats/verify/simulation/wayside/memory/wayside_memory_train.go +++ b/ats/verify/simulation/wayside/memory/wayside_memory_train.go @@ -77,6 +77,13 @@ func RemoveTrainState(simulation *VerifySimulation, id string) { d, ok := allTrainMap.Load(id) if ok { t := d.(*state.TrainState) + trainIndex, _ := strconv.ParseUint(id, 10, 16) + httpCode, _, err := dynamics.SendRemoveTrainReq(&dynamics.InitTrainInfo{ + TrainIndex: uint16(trainIndex), + }) + if err != nil || httpCode != http.StatusOK { + panic(dto.ErrorDto{Code: dto.LogicError, Message: fmt.Sprintf("动力学接口调用失败:[%d][%s]", httpCode, err)}) + } // 从仿真内存中移除列车 t.Show = false allTrainMap.Store(id, t) diff --git a/dynamics/http.go b/dynamics/http.go index 41877cb..22b3db2 100644 --- a/dynamics/http.go +++ b/dynamics/http.go @@ -4,9 +4,10 @@ import ( "bytes" "encoding/json" "fmt" - "joylink.club/bj-rtsts-server/config" "net/http" "time" + + "joylink.club/bj-rtsts-server/config" ) func SendInitTrainReq(info *InitTrainInfo) (int, *[]byte, error) { @@ -31,6 +32,28 @@ func SendInitTrainReq(info *InitTrainInfo) (int, *[]byte, error) { return resp.StatusCode, &buf, resp.Body.Close() } +func SendRemoveTrainReq(info *InitTrainInfo) (int, *[]byte, error) { + baseUrl := getUrlBase() + uri := "/api/aerodynamics/remove/train/" + url := baseUrl + uri + data, _ := json.Marshal(info) + client := http.Client{ + Timeout: time.Second * 5, + } + resp, err := client.Post(url, "application/json", bytes.NewBuffer(data)) + if err != nil { + s := err.Error() + println(s) + return 0, nil, err + } + var buf []byte + _, err = resp.Body.Read(buf) + if err != nil { + return resp.StatusCode, nil, err + } + return resp.StatusCode, &buf, resp.Body.Close() +} + func SendSimulationStartReq(base *LineBaseInfo) (int, *[]byte, error) { baseUrl := getUrlBase() uri := "/api/start/"