From a6b806130e89bc72f590c693de421cd451622f27 Mon Sep 17 00:00:00 2001 From: xzb <223@qq.com> Date: Fri, 28 Jul 2023 14:36:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0ats=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/simulation.go | 73 +++++++++++++++++++++++++++++++++++++++++++++++ dto/simulation.go | 39 +++++++++++++++++++++++++ main.go | 1 + 3 files changed, 113 insertions(+) create mode 100644 api/simulation.go create mode 100644 dto/simulation.go diff --git a/api/simulation.go b/api/simulation.go new file mode 100644 index 0000000..dd1e428 --- /dev/null +++ b/api/simulation.go @@ -0,0 +1,73 @@ +package api + +import ( + "fmt" + "net/http" + + jwt "github.com/appleboy/gin-jwt/v2" + "github.com/gin-gonic/gin" + "go.uber.org/zap" + "joylink.club/bj-rtsts-server/dto" +) + +func InitSimulationRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) { + authed := api.Group("/v1/simulation").Use(authMiddleware.MiddlewareFunc()) + authed.POST("/create", create) + authed.POST("/train/add", addTrain) +} + +// 创建ATS测试仿真 +// +// @Summary 创建ATS测试仿真 +// +// @Security JwtAuth +// +// @Description 创建ATS测试仿真 +// @Tags ATS测试仿真Api +// @Accept json +// @Produce json +// @Param Authorization header string true "JWT Token" +// @Param SimulationCreateReqDto body dto.SimulationCreateReqDto true "创建仿真请求" +// @Success 200 {object} dto.SimulationCreateRspDto +// @Failure 500 {object} dto.ErrorDto +// @Router /api/v1/simulation/create [post] +func create(c *gin.Context) { + //user,_:=c.Get(middleware.IdentityKey) + req := dto.SimulationCreateReqDto{} + if err := c.ShouldBind(&req); nil != err { + panic(err) + } + zap.S().Debug("创建仿真请求:", req) + rsp := dto.SimulationCreateRspDto{} + rsp.MapId = req.MapId + rsp.SimulationId = fmt.Sprintf("sim-%d", req.MapId) + 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) + } + zap.S().Debug("ATS测试仿真-添加列车,请求:", req) + rsp := dto.AddTrainRspDto{} + rsp.SimulationId = req.SimulationId + rsp.TrainId = "666" + c.JSON(http.StatusOK, &rsp) +} diff --git a/dto/simulation.go b/dto/simulation.go new file mode 100644 index 0000000..457a713 --- /dev/null +++ b/dto/simulation.go @@ -0,0 +1,39 @@ +package dto + +//创建仿真请求 +type SimulationCreateReqDto struct { + //地图id + MapId int32 `json:"mapId" form:"mapId"` +} + +//创建仿真响应 +type SimulationCreateRspDto struct { + //地图id + MapId int32 `json:"mapId" form:"mapId"` + //仿真id + SimulationId string `json:"simulationId" form:"simulationId"` +} + +////////////////////////////////////////////////////////////////////////////// + +// 为仿真添加测试车请求 +type AddTrainReqDto struct { + //仿真id + SimulationId string `json:"simulationId" form:"simulationId"` + //列车方向,true-上行,false-下行 + Up bool `json:"up" form:"up"` + //车头所在link的索引 + HeadLinkId string `json:"headLinkId" form:"headLinkId"` + //车头所在link内的偏移量,单位为mm + HeadLinkOffset int64 `json:"headLinkOffset" form:"headLinkOffset"` +} + +//为仿真添加测试车请求 +type AddTrainRspDto struct { + //仿真id + SimulationId string `json:"simulationId" form:"simulationId"` + //新添加的列车的索引 + TrainId string `json:"trainId" form:"trainId"` +} + +///////////////////////////////////////////////////////////////////////////////// diff --git a/main.go b/main.go index d842fd4..434fece 100644 --- a/main.go +++ b/main.go @@ -30,6 +30,7 @@ func main() { api.InitUserRouter(router, authMiddleware) api.InitDraftingRouter(router, authMiddleware) api.InitPublishedGiRouter(router, authMiddleware) + api.InitSimulationRouter(router, authMiddleware) docs.SwaggerInfo.Title = "CBTC测试系统API" engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))