【增加动力学移除列车接口】

This commit is contained in:
weizhihong 2023-08-16 09:29:28 +08:00
parent 7c8f7b5b94
commit 289034b364
2 changed files with 31 additions and 1 deletions

View File

@ -77,6 +77,13 @@ func RemoveTrainState(simulation *VerifySimulation, id string) {
d, ok := allTrainMap.Load(id) d, ok := allTrainMap.Load(id)
if ok { if ok {
t := d.(*state.TrainState) 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 t.Show = false
allTrainMap.Store(id, t) allTrainMap.Store(id, t)

View File

@ -4,9 +4,10 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"fmt" "fmt"
"joylink.club/bj-rtsts-server/config"
"net/http" "net/http"
"time" "time"
"joylink.club/bj-rtsts-server/config"
) )
func SendInitTrainReq(info *InitTrainInfo) (int, *[]byte, error) { 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() 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) { func SendSimulationStartReq(base *LineBaseInfo) (int, *[]byte, error) {
baseUrl := getUrlBase() baseUrl := getUrlBase()
uri := "/api/start/" uri := "/api/start/"