【修改仿真接口逻辑】
This commit is contained in:
parent
e2e7512057
commit
b1e8a39fe3
|
@ -1,12 +1,19 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
jwt "github.com/appleboy/gin-jwt/v2"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"go.uber.org/zap"
|
||||
"joylink.club/bj-rtsts-server/ats/verify/protos/graphicData"
|
||||
"joylink.club/bj-rtsts-server/ats/verify/protos/state"
|
||||
"joylink.club/bj-rtsts-server/ats/verify/simulation"
|
||||
"joylink.club/bj-rtsts-server/ats/verify/simulation/wayside"
|
||||
"joylink.club/bj-rtsts-server/dto"
|
||||
apiproto "joylink.club/bj-rtsts-server/grpcproto"
|
||||
"joylink.club/bj-rtsts-server/service"
|
||||
|
@ -17,8 +24,8 @@ func InitSimulationRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddle
|
|||
authed.POST("/create", create)
|
||||
authed.POST("/destroy/:id", destroy)
|
||||
authed.GET("/list", findAllSimulations)
|
||||
authed.POST("/train/add", addTrain)
|
||||
authed.POST("/check/data", checkSimMapData)
|
||||
authed.POST("/train/add", addTrain)
|
||||
authed.POST("/train/remove", removeTrain)
|
||||
authed.POST("/switch/operation", switchOperation)
|
||||
|
||||
|
@ -47,39 +54,11 @@ func create(c *gin.Context) {
|
|||
panic(err)
|
||||
}
|
||||
zap.S().Debug("创建仿真请求:", req)
|
||||
rsp := dto.SimulationCreateRspDto{}
|
||||
rsp.MapId = req.MapId
|
||||
//rsp.SimulationId = fmt.Sprintf("sim-%d", req.MapId)
|
||||
mapData := service.QueryRtssGraphicStorage(req.MapId)
|
||||
rsp.SimulationId = simulation.CreateSimulation(int(rsp.MapId), mapData)
|
||||
c.JSON(http.StatusOK, &rsp)
|
||||
}
|
||||
|
||||
// ATS测试仿真-添加列车
|
||||
//
|
||||
// @Summary ATS测试仿真-添加列车
|
||||
//
|
||||
// @Security JwtAuth
|
||||
//
|
||||
// @Description ATS测试仿真-添加列车
|
||||
// @Tags ATS测试仿真Api
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param Authorization header string true "JWT Token"
|
||||
// @Param AddTrainReqDto body dto.AddTrainReqDto true "ATS测试仿真-添加列车"
|
||||
// @Success 200 {object} dto.AddTrainRspDto
|
||||
// @Failure 500 {object} dto.ErrorDto
|
||||
// @Router /api/v1/simulation/train/add [post]
|
||||
func addTrain(c *gin.Context) {
|
||||
//user,_:=c.Get(middleware.IdentityKey)
|
||||
req := dto.AddTrainReqDto{}
|
||||
if err := c.ShouldBind(&req); nil != err {
|
||||
panic(err)
|
||||
rsp := dto.SimulationCreateRspDto{
|
||||
MapId: req.MapId,
|
||||
}
|
||||
zap.S().Debug("ATS测试仿真-添加列车,请求:", req)
|
||||
rsp := dto.AddTrainRspDto{}
|
||||
rsp.SimulationId = req.SimulationId
|
||||
rsp.TrainId = "666"
|
||||
mapData := service.QueryRtssGraphicStorage(req.MapId)
|
||||
rsp.SimulationId = simulation.CreateSimulation(int(req.MapId), mapData)
|
||||
c.JSON(http.StatusOK, &rsp)
|
||||
}
|
||||
|
||||
|
@ -122,8 +101,16 @@ func destroy(c *gin.Context) {
|
|||
// @Router /api/v1/simulation/list [get]
|
||||
func findAllSimulations(c *gin.Context) {
|
||||
zap.S().Debug("ATS测试仿真-获取ATS测试系统所有仿真实例的基本信息,请求")
|
||||
simArr := [...]dto.SimulationInfoRepDto{}
|
||||
i := 0
|
||||
for v := range simulation.SimulationMap {
|
||||
simArr[i] = dto.SimulationInfoRepDto{
|
||||
SimulationId: v,
|
||||
MapId: strings.Split(v, "_")[0],
|
||||
}
|
||||
}
|
||||
//TODO 后续调用
|
||||
c.JSON(http.StatusOK, dto.SimulationInfoRepDtoArr{dto.SimulationInfoRepDto{"1", "123"}, dto.SimulationInfoRepDto{"2", "333"}})
|
||||
c.JSON(http.StatusOK, simArr)
|
||||
}
|
||||
|
||||
// ATS测试仿真地图数据校验
|
||||
|
@ -143,17 +130,62 @@ func findAllSimulations(c *gin.Context) {
|
|||
// @Failure 500 {object} dto.ErrorDto
|
||||
// @Router /api/v1/simulation/check/data [post]
|
||||
func checkSimMapData(c *gin.Context) {
|
||||
rt := &dto.CheckMapDataRspDto{}
|
||||
err := c.Bind(rt)
|
||||
rt := &dto.CheckMapDataReqDto{}
|
||||
if err := c.ShouldBind(&rt); nil != err {
|
||||
panic(err)
|
||||
}
|
||||
err := proto.Unmarshal(rt.Data, &graphicData.RtssGraphicStorage{})
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, "参数错误")
|
||||
|
||||
} else {
|
||||
//TODO 后续调用
|
||||
c.JSON(http.StatusOK, dto.CheckMapDataRspDto{true, []string{"error"}})
|
||||
c.JSON(http.StatusOK, &dto.CheckMapDataRspDto{Success: true})
|
||||
}
|
||||
}
|
||||
|
||||
// ATS测试仿真-添加列车
|
||||
//
|
||||
// @Summary ATS测试仿真-添加列车
|
||||
//
|
||||
// @Security JwtAuth
|
||||
//
|
||||
// @Description ATS测试仿真-添加列车
|
||||
// @Tags ATS测试仿真Api
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param Authorization header string true "JWT Token"
|
||||
// @Param AddTrainReqDto body dto.AddTrainReqDto true "ATS测试仿真-添加列车"
|
||||
// @Success 200 {object} dto.AddTrainRspDto
|
||||
// @Failure 500 {object} dto.ErrorDto
|
||||
// @Router /api/v1/simulation/train/add [post]
|
||||
func addTrain(c *gin.Context) {
|
||||
//user,_:=c.Get(middleware.IdentityKey)
|
||||
req := dto.AddTrainReqDto{}
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
zap.S().Debug("ATS测试仿真-添加列车,请求:", req)
|
||||
deviceMemory := checkDeviceDataAndReturn(req.SimulationId)
|
||||
trainMap := deviceMemory.Status.TrainStateMap
|
||||
// 获取列车ID
|
||||
i := 1
|
||||
for {
|
||||
if trainMap[strconv.Itoa(i)] == nil {
|
||||
break
|
||||
} else {
|
||||
i++
|
||||
}
|
||||
}
|
||||
id := strconv.Itoa(i)
|
||||
rsp := &state.TrainState{
|
||||
Id: id,
|
||||
HeadLinkId: req.HeadLinkId,
|
||||
HeadLinkOffset: req.HeadLinkOffset,
|
||||
Up: req.Up,
|
||||
}
|
||||
trainMap[id] = rsp
|
||||
c.JSON(http.StatusOK, &rsp)
|
||||
}
|
||||
|
||||
// ATS测试仿真-移除列车
|
||||
//
|
||||
// @Summary ATS测试仿真-移除列车
|
||||
|
@ -172,15 +204,14 @@ func checkSimMapData(c *gin.Context) {
|
|||
// @Router /api/v1/simulation/train/remove [post]
|
||||
func removeTrain(c *gin.Context) {
|
||||
rt := &dto.RemoveTrainDto{}
|
||||
err := c.Bind(rt)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, "参数错误")
|
||||
|
||||
} else {
|
||||
//TODO 后续调用列车删除操作
|
||||
c.JSON(http.StatusOK, "ok")
|
||||
if err := c.ShouldBind(&rt); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
zap.S().Debug("ATS测试仿真-移除列车,请求:", rt)
|
||||
deviceMemory := checkDeviceDataAndReturn(rt.SimulationId)
|
||||
delete(deviceMemory.Status.TrainStateMap, rt.TrainId)
|
||||
//TODO 后续调用列车删除操作
|
||||
c.JSON(http.StatusOK, "ok")
|
||||
}
|
||||
|
||||
// 获取ATS测试-操作道岔
|
||||
|
@ -200,13 +231,25 @@ func removeTrain(c *gin.Context) {
|
|||
// @Failure 500 {object} dto.ErrorDto
|
||||
// @Router /api/v1/simulation/switch/operation [post]
|
||||
func switchOperation(c *gin.Context) {
|
||||
switchOper := &dto.SwitchOperationReqDto{}
|
||||
err := c.Bind(switchOper)
|
||||
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, "参数错误")
|
||||
} else {
|
||||
//TODO 后续调用道岔操作
|
||||
c.JSON(http.StatusOK, "ok")
|
||||
req := &dto.SwitchOperationReqDto{}
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
deviceMemory := checkDeviceDataAndReturn(req.SimulationId)
|
||||
switchInfo := deviceMemory.Status.SwitchStateMap[req.SwitchIndex]
|
||||
if switchInfo == nil {
|
||||
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("仿真[%s]中索引为[%s]的道岔不存在", req.SimulationId, req.SwitchIndex)})
|
||||
}
|
||||
switchInfo.Normal = req.TurnNormal
|
||||
switchInfo.Reverse = req.TurnReverse
|
||||
c.JSON(http.StatusOK, "ok")
|
||||
}
|
||||
|
||||
// 获取仿真设备数据并返回
|
||||
func checkDeviceDataAndReturn(simId string) *wayside.VerifyMemory {
|
||||
deviceMemory := simulation.FindSimulation(simId)
|
||||
if deviceMemory == nil {
|
||||
panic(&dto.ErrorDto{Code: dto.DataNotExist, Message: fmt.Sprintf("仿真[%s]不存在", simId)})
|
||||
}
|
||||
return deviceMemory
|
||||
}
|
||||
|
|
|
@ -46,8 +46,8 @@ type RemoveTrainDto AddTrainRspDto
|
|||
type SwitchOperationReqDto struct {
|
||||
SimulationId string `form:"simulationId" json:"simulationId" binding:"required"`
|
||||
SwitchIndex string `form:"switchIndex" json:"switchIndex" binding:"required"`
|
||||
TurnNormal bool `form:"turnNormal" json:"turnNormal" binding:"required"`
|
||||
TurnReverse bool `form:"turnReverse" json:"turnReverse" binding:"required"`
|
||||
TurnNormal bool `form:"turnNormal" json:"turnNormal"`
|
||||
TurnReverse bool `form:"turnReverse" json:"turnReverse"`
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -67,10 +67,11 @@ func generateTestState(v *wayside.VerifyMemory) *state.PushedDevicesStatus {
|
|||
if len(switchMap) == 0 {
|
||||
for i := 0; i < 9; i++ {
|
||||
switchArr[i] = &state.SwitchState{
|
||||
Id: strconv.Itoa(i),
|
||||
Id: strconv.Itoa(i + 1),
|
||||
Normal: true,
|
||||
Reverse: false,
|
||||
}
|
||||
v.Status.SwitchStateMap[strconv.Itoa(i+1)] = switchArr[i]
|
||||
}
|
||||
} else {
|
||||
i := 0
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"joylink.club/bj-rtsts-server/ats/verify/protos/graphicData"
|
||||
)
|
||||
|
||||
// 查询地图数据
|
||||
func QueryRtssGraphicStorage(mapId int32) *graphicData.RtssGraphicStorage {
|
||||
publishdata, err := GetPublishedGiById(int(mapId))
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue