【增加动力学移除列车接口】
This commit is contained in:
parent
7c8f7b5b94
commit
289034b364
@ -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)
|
||||
|
@ -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/"
|
||||
|
Loading…
Reference in New Issue
Block a user