From 289034b364f59bce7de00426288cdccc2e13821c Mon Sep 17 00:00:00 2001 From: weizhihong Date: Wed, 16 Aug 2023 09:29:28 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=A2=9E=E5=8A=A0=E5=8A=A8=E5=8A=9B?= =?UTF-8?q?=E5=AD=A6=E7=A7=BB=E9=99=A4=E5=88=97=E8=BD=A6=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E3=80=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wayside/memory/wayside_memory_train.go | 7 ++++++ dynamics/http.go | 25 ++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) 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/"