787 lines
25 KiB
Go
787 lines
25 KiB
Go
package api
|
||
|
||
import (
|
||
"fmt"
|
||
"log/slog"
|
||
"net/http"
|
||
"sort"
|
||
"strconv"
|
||
|
||
jwt "github.com/appleboy/gin-jwt/v2"
|
||
"github.com/gin-gonic/gin"
|
||
"github.com/golang/protobuf/proto"
|
||
"joylink.club/bj-rtsts-server/dto"
|
||
"joylink.club/bj-rtsts-server/dto/data_proto"
|
||
"joylink.club/bj-rtsts-server/dto/request_proto"
|
||
"joylink.club/bj-rtsts-server/dto/state_proto"
|
||
"joylink.club/bj-rtsts-server/middleware"
|
||
"joylink.club/bj-rtsts-server/service"
|
||
"joylink.club/bj-rtsts-server/sys_error"
|
||
"joylink.club/bj-rtsts-server/ts"
|
||
"joylink.club/bj-rtsts-server/ts/simulation/wayside/memory"
|
||
)
|
||
|
||
func InitSimulationRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||
authed := api.Group("/v1/simulation").Use(authMiddleware.MiddlewareFunc(), middleware.PermissMiddleware)
|
||
authed.POST("/createByProject", createByProjectId)
|
||
authed.POST("/destroy/:id", destroy)
|
||
authed.GET("/list", findAllSimulations)
|
||
authed.POST("/check/data", checkSimMapData)
|
||
authed.POST("/train/add", addTrain)
|
||
authed.POST("/train/config", configTrain)
|
||
authed.POST("/train/remove", removeTrain)
|
||
authed.POST("/train/update", updateTrain)
|
||
authed.POST("/switch/operation", turnoutOperation)
|
||
authed.POST("/relay/operation", relayOperation)
|
||
authed.POST("/signal/operation", signalOperation)
|
||
authed.POST("/axleSection/operation", axleSectionOperation)
|
||
authed.POST("/esbBtn/operation", esbBtnOperation)
|
||
authed.POST("/ibp/btn/operation", ibpBtnOperation)
|
||
authed.POST("/ibp/key/operation", ibpKeyOperation)
|
||
authed.GET("/:id/getMapKilometerRange", getMapKilometerRange)
|
||
authed.POST("/psl/operation", pslBtnOperation)
|
||
authed.POST("/psd/operation", psdOperation)
|
||
authed.PUT("/balise/position/modify", balisePositionModify)
|
||
authed.PUT("/balise/position/reset", transponderPositionReset)
|
||
authed.PUT("/balise/telegram/modify", baliseTelegramModify)
|
||
authed.PUT("/balise/telegram/reset", baliseTelegramReset)
|
||
authed.PUT("/balise/reset", baliseReset)
|
||
|
||
// 初始化地图信息
|
||
initPublishMapInfo()
|
||
}
|
||
|
||
func initPublishMapInfo() {
|
||
mapArr := service.ListAllPublished()
|
||
sort.SliceStable(mapArr, func(i, j int) bool { return mapArr[i].Type != 0 })
|
||
for _, v := range mapArr {
|
||
memory.PublishMapVerifyStructure(v)
|
||
}
|
||
}
|
||
|
||
// 创建ATS测试仿真通过项目ID
|
||
//
|
||
// @Summary 创建ATS测试仿真
|
||
//
|
||
// @Security JwtAuth
|
||
//
|
||
// @Description 创建ATS测试仿真通过项目ID
|
||
// @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/createByProject [post]
|
||
func createByProjectId(c *gin.Context) {
|
||
req := dto.SimulationCreateReqDto{}
|
||
if err := c.ShouldBind(&req); nil != err {
|
||
panic(sys_error.New("测试启动失败,请求参数异常", err))
|
||
}
|
||
// 地图信息
|
||
mapInfos := service.QueryProjectPublished(req.ProjectId)
|
||
if len(mapInfos) == 0 {
|
||
panic(sys_error.New("测试启动失败,项目未关联发布图"))
|
||
}
|
||
var mapIds []int32
|
||
for _, mapInfo := range mapInfos {
|
||
if mapInfo.Type == data_proto.PictureType_value[data_proto.PictureType_TrainData.String()] {
|
||
continue
|
||
}
|
||
mapIds = append(mapIds, mapInfo.ID)
|
||
}
|
||
// 运行环境配置
|
||
runConfig := service.QueryRunConfig(req.ProjectRunConfigId)
|
||
simulationId, err := ts.CreateSimulation(req.ProjectId, mapIds, runConfig)
|
||
if err != nil {
|
||
panic(sys_error.New("测试启动失败", err))
|
||
}
|
||
rsp := dto.SimulationCreateRspDto{
|
||
ProjectId: req.ProjectId,
|
||
MapId: mapIds[0],
|
||
MapIds: mapIds,
|
||
ProjectRunConfigId: req.ProjectRunConfigId,
|
||
}
|
||
rsp.SimulationId = simulationId
|
||
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 id path int true "仿真id"
|
||
// @Success 200 {object} string
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/destroy/{id} [post]
|
||
func destroy(c *gin.Context) {
|
||
simId := c.Param("id")
|
||
slog.Debug("ATS测试仿真-ATS仿真销毁 请求:", simId)
|
||
ts.DestroySimulation(simId)
|
||
c.JSON(http.StatusOK, "ok")
|
||
}
|
||
|
||
// 获取ATS测试系统所有仿真实例的基本信息
|
||
//
|
||
// @Summary 获取ATS测试系统所有仿真实例的基本信息
|
||
//
|
||
// @Security JwtAuth
|
||
//
|
||
// @Description 获取ATS测试系统所有仿真实例的基本信息
|
||
// @Tags ATS测试仿真Api
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param Authorization header string true "JWT Token"
|
||
// @Success 200 {object} dto.SimulationInfoRspDtoArr
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/list [get]
|
||
func findAllSimulations(c *gin.Context) {
|
||
c.JSON(http.StatusOK, ts.ListAllSimulations())
|
||
}
|
||
|
||
// ATS测试仿真地图数据校验
|
||
//
|
||
// @Summary ATS测试仿真地图数据校验
|
||
//
|
||
// @Security JwtAuth
|
||
//
|
||
// @Description 地图数据校验
|
||
// @Tags ATS测试仿真Api
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param Authorization header string true "JWT Token"
|
||
// @Param RemoveTrainDto body dto.CheckMapDataReqDto true "ATS测试仿真-地图数据"
|
||
//
|
||
// @Success 200 {object} dto.CheckMapDataRspDto
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/check/data [post]
|
||
func checkSimMapData(c *gin.Context) {
|
||
rt := &dto.CheckMapDataReqDto{}
|
||
if err := c.ShouldBind(&rt); nil != err {
|
||
panic(sys_error.New("请求参数异常", err))
|
||
}
|
||
err := proto.Unmarshal(rt.Data, &data_proto.RtssGraphicStorage{})
|
||
if err != nil {
|
||
panic(sys_error.New("非平面布置图数据"))
|
||
}
|
||
c.JSON(http.StatusOK, &dto.CheckMapDataRspDto{Success: true})
|
||
}
|
||
|
||
// 列车动力学参数配置修改
|
||
//
|
||
// @Summary 列车动力学参数配置修改
|
||
//
|
||
// @Security JwtAuth
|
||
//
|
||
// @Description 地图数据校验
|
||
// @Tags ATS测试仿真Api
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param Authorization header string true "JWT Token"
|
||
// @Param RemoveTrainDto body dto.ConfigTrainReqDto true "动力学参数配置"
|
||
//
|
||
// @Success 200 {object} string
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/train/config [post]
|
||
func configTrain(c *gin.Context) {
|
||
req := &dto.ConfigTrainReqDto{}
|
||
if err := c.ShouldBind(&req); err != nil {
|
||
panic(sys_error.New("修改列车配置失败,请求参数异常", err))
|
||
}
|
||
simulation := checkDeviceDataAndReturn(req.SimulationId)
|
||
memory.UpdateConfigTrain(simulation, req)
|
||
c.JSON(http.StatusOK, "ok")
|
||
}
|
||
|
||
// 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.AddTrainReqDtoNew true "ATS测试仿真-添加列车"
|
||
// @Success 200 {object} dto.AddTrainRspDto
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/train/add [post]
|
||
func addTrain(c *gin.Context) {
|
||
//req := dto.AddTrainReqDto{}
|
||
req := dto.AddTrainReqDtoNew{}
|
||
if err := c.ShouldBind(&req); err != nil {
|
||
panic(sys_error.New("添加列车失败,请求参数异常", err))
|
||
}
|
||
simulation := checkDeviceDataAndReturn(req.SimulationId)
|
||
id := getAddTrainPrimaryKey(simulation)
|
||
if id == -1 {
|
||
panic(sys_error.New("添加列车失败,已有列车在运行"))
|
||
}
|
||
rsp := &state_proto.TrainState{
|
||
Id: strconv.Itoa(id),
|
||
HeadDeviceId: req.Id,
|
||
HeadOffset: req.HeadOffset,
|
||
DevicePort: req.DevicePort,
|
||
RunDirection: req.RunDirection,
|
||
TrainLength: req.TrainLength,
|
||
WheelDiameter: req.WheelDiameter,
|
||
/*TrainDynamicConfig: &state_proto.TrainDynamicConfig{
|
||
//int32 mass=1;
|
||
//基本阻力参数A
|
||
BaseResistanceParamA: req.ConfigTrain.BaseResistanceParamA,
|
||
// 基本阻力参数B
|
||
BaseResistanceParamB: req.ConfigTrain.BaseResistanceParamB,
|
||
// 基本阻力参数C
|
||
BaseResistanceParamC: req.ConfigTrain.BaseResistanceParamC,
|
||
//曲线阻力参数R1
|
||
CurveResistanceParamR1: req.ConfigTrain.CurveResistanceParamR1,
|
||
// 曲线阻力参数R2
|
||
CurveResistanceParamR2: req.ConfigTrain.CurveResistanceParamR2,
|
||
// 曲线阻力参数R3
|
||
CurveResistanceParamR3: req.ConfigTrain.CurveResistanceParamR3,
|
||
// 曲线阻力参数R4
|
||
CurveResistanceParamR4: req.ConfigTrain.CurveResistanceParamR4,
|
||
//旋转质量参数
|
||
RevolvingMassParam: req.ConfigTrain.RevolvingMassParam,
|
||
//是否跳跃
|
||
Jump: req.ConfigTrain.Jump,
|
||
//打滑(%)
|
||
Slip: req.ConfigTrain.Slip,
|
||
//前溜/后溜(mm)(正数前溜,负数后溜)
|
||
Slide: req.ConfigTrain.Slide,
|
||
//过标/欠标(mm)(正数过标,负数欠标)
|
||
StopSign: req.ConfigTrain.StopSign,
|
||
//车径
|
||
//WheelDiameter: req.ConfigTrain.WheelDiameter,
|
||
TrainEndsA: memory.DtoTrainEndsToStateProto(req.ConfigTrain.TrainEndsA),
|
||
TrainEndsB: memory.DtoTrainEndsToStateProto(req.ConfigTrain.TrainEndsB),
|
||
},*/
|
||
}
|
||
memory.AddTrainStateNew(simulation, rsp, req.ConfigTrain, req.TrainEndsA, req.TrainEndsB, 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 UpdateTrainReqDto body dto.UpdateTrainReqDto true "ATS测试仿真-修改列车基础信息"
|
||
// @Success 200 {object} dto.AddTrainRspDto
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/train/update [post]
|
||
func updateTrain(c *gin.Context) {
|
||
req := dto.UpdateTrainReqDto{}
|
||
if err := c.ShouldBind(&req); err != nil {
|
||
panic(sys_error.New("添加列车失败,请求参数异常", err))
|
||
}
|
||
simulation := checkDeviceDataAndReturn(req.SimulationId)
|
||
rsp := &state_proto.TrainState{
|
||
Id: req.Id,
|
||
TrainLength: req.TrainLength,
|
||
WheelDiameter: req.WheelDiameter,
|
||
}
|
||
memory.UpdateTrainInfo(simulation, rsp)
|
||
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 RemoveTrainDto body dto.RemoveTrainDto true "ATS测试仿真-移除列车"
|
||
//
|
||
// @Success 200 {object} string
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/train/remove [post]
|
||
func removeTrain(c *gin.Context) {
|
||
rt := &dto.RemoveTrainDto{}
|
||
if err := c.ShouldBind(&rt); err != nil {
|
||
panic(sys_error.New("移除列车失败,请求参数异常", err))
|
||
}
|
||
slog.Debug("ATS测试仿真-移除列车,请求:", rt)
|
||
simulation := checkDeviceDataAndReturn(rt.SimulationId)
|
||
memory.RemoveTrainState(simulation, rt.TrainId)
|
||
//TODO 后续调用列车删除操作
|
||
c.JSON(http.StatusOK, "ok")
|
||
}
|
||
|
||
// 获取ATS测试-操作道岔
|
||
//
|
||
// @Summary 获取ATS测试-操作道岔
|
||
//
|
||
// @Security JwtAuth
|
||
//
|
||
// @Description ATS测试-操作道岔
|
||
// @Tags ATS测试仿真Api
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param Authorization header string true "JWT Token"
|
||
// @Param TurnoutOperationReq body request_proto.TurnoutOperationReq true "ATS测试仿真-操作道岔"
|
||
//
|
||
// @Success 200 {object} string
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/switch/operation [post]
|
||
func turnoutOperation(c *gin.Context) {
|
||
req := &request_proto.TurnoutOperationReq{}
|
||
if err := c.ShouldBind(&req); err != nil {
|
||
panic(sys_error.New("道岔操作失败,请求参数异常", err))
|
||
}
|
||
simulation := checkDeviceDataAndReturn(req.SimulationId)
|
||
slog.Info("传入状态参数", "request", req)
|
||
err := memory.HandleTurnoutOperation(simulation, req)
|
||
if err != nil {
|
||
panic(sys_error.New(fmt.Sprintf("道岔操作失败, %s", err), err))
|
||
}
|
||
c.JSON(http.StatusOK, "ok")
|
||
}
|
||
|
||
// ATS测试-信号机操作
|
||
//
|
||
// @Summary ATS测试-信号机操作
|
||
//
|
||
// @Security JwtAuth
|
||
//
|
||
// @Description ATS测试-信号机操作
|
||
// @Tags ATS测试仿真Api
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param Authorization header string true "JWT Token"
|
||
// @Param SignalOperationReqDto body dto.SignalOperationReqDto true "ATS测试仿真-操作信号机"
|
||
//
|
||
// @Success 200 {object} string
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/signal/operation [post]
|
||
func signalOperation(c *gin.Context) {
|
||
req := &dto.SignalOperationReqDto{}
|
||
if err := c.ShouldBind(&req); err != nil {
|
||
panic(sys_error.New("输入参数格式错误", err))
|
||
}
|
||
simulation := checkDeviceDataAndReturn(req.SimulationId)
|
||
slog.Info("传入状态参数", req)
|
||
memory.ChangeSignalState(simulation, req)
|
||
c.JSON(http.StatusOK, "ok")
|
||
}
|
||
|
||
// ATS测试-计轴区段操作
|
||
//
|
||
// @Summary ATS测试-计轴区段操作
|
||
//
|
||
// @Security JwtAuth
|
||
//
|
||
// @Description ATS测试-计轴区段操作
|
||
// @Tags ATS测试仿真Api
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param Authorization header string true "JWT Token"
|
||
// @Param AxleSectionOperationReqDto body dto.AxleSectionOperationReqDto true "ATS测试仿真-操作计轴区段"
|
||
//
|
||
// @Success 200 {object} string
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/axleSection/operation [post]
|
||
func axleSectionOperation(c *gin.Context) { //操作:设置故障占用、取消故障占用
|
||
req := &dto.AxleSectionOperationReqDto{}
|
||
if err := c.ShouldBind(&req); err != nil {
|
||
panic(sys_error.New("输入参数格式错误", err))
|
||
}
|
||
simulation := checkDeviceDataAndReturn(req.SimulationId)
|
||
slog.Info("传入状态参数", req)
|
||
err := memory.ChangeAxleSectionState(simulation, req)
|
||
if err != nil {
|
||
panic(sys_error.New("操作失败", err))
|
||
}
|
||
c.JSON(http.StatusOK, "ok")
|
||
}
|
||
|
||
// ATS测试-ESB按钮操作
|
||
//
|
||
// @Summary ATS测试-ESB按钮操作
|
||
//
|
||
// @Security JwtAuth
|
||
//
|
||
// @Description ATS测试-ESB按钮操作
|
||
// @Tags ATS测试仿真Api
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param Authorization header string true "JWT Token"
|
||
// @Param EsbButtonOperationReqDto body dto.EsbButtonOperationReqDto true "ATS测试仿真-ESB按钮操作"
|
||
//
|
||
// @Success 200 {object} string
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/esbBtn/operation [post]
|
||
func esbBtnOperation(c *gin.Context) {
|
||
req := &dto.EsbButtonOperationReqDto{}
|
||
if err := c.ShouldBind(&req); err != nil {
|
||
panic(sys_error.New("紧急关闭按钮操作失败,请求参数异常", err))
|
||
}
|
||
simulation := checkDeviceDataAndReturn(req.SimulationId)
|
||
slog.Info("传入状态参数", req)
|
||
err := memory.ChangeEsbButtonState(simulation, req.MapId, req.Id, req.Down)
|
||
if err != nil {
|
||
panic(sys_error.New(fmt.Sprintf("紧急关闭按钮操作失败,%s", err.Error()), err))
|
||
}
|
||
c.JSON(http.StatusOK, "ok")
|
||
}
|
||
|
||
// ATS测试-IBP按钮操作
|
||
//
|
||
// @Summary ATS测试-IBP按钮操作
|
||
//
|
||
// @Security JwtAuth
|
||
//
|
||
// @Description ATS测试-IBP按钮操作
|
||
// @Tags ATS测试仿真Api
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param Authorization header string true "JWT Token"
|
||
// @Param IBPButtonOperationReqDto body dto.IBPButtonOperationReqDto true "ATS测试仿真-IBP按钮操作"
|
||
//
|
||
// @Success 200 {object} string
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/ibp/btn/operation [post]
|
||
func ibpBtnOperation(c *gin.Context) {
|
||
req := &dto.IBPButtonOperationReqDto{}
|
||
if err := c.ShouldBind(&req); err != nil {
|
||
panic(sys_error.New("IBP按钮操作失败,请求参数异常", err))
|
||
}
|
||
simulation := checkDeviceDataAndReturn(req.SimulationId)
|
||
slog.Info("传入状态参数", req)
|
||
err := memory.ChangeIBPButtonState(simulation, req.MapId, req.StationId, req.ButtonId, req.Down)
|
||
if err != nil {
|
||
panic(sys_error.New(fmt.Sprintf("IBP按钮操作失败,%s", err.Error()), err))
|
||
}
|
||
c.JSON(http.StatusOK, "ok")
|
||
}
|
||
|
||
// ATS测试-IBP钥匙操作
|
||
//
|
||
// @Summary ATS测试-IBP钥匙操作
|
||
//
|
||
// @Security JwtAuth
|
||
//
|
||
// @Description ATS测试-IBP钥匙操作
|
||
// @Tags ATS测试仿真Api
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param Authorization header string true "JWT Token"
|
||
// @Param KeyOperationReqDto body dto.KeyOperationReqDto true "ATS测试仿真-IBP钥匙操作"
|
||
//
|
||
// @Success 200 {object} string
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/ibp/key/operation [post]
|
||
func ibpKeyOperation(c *gin.Context) {
|
||
req := &dto.KeyOperationReqDto{}
|
||
if err := c.ShouldBind(&req); err != nil {
|
||
panic(sys_error.New("IBP开关操作失败,请求参数异常", err))
|
||
}
|
||
simulation := checkDeviceDataAndReturn(req.SimulationId)
|
||
slog.Info("传入状态参数", req)
|
||
err := memory.ChangeIBPKeyState(simulation, req.MapId, req.StationId, req.KeyId, req.Gear)
|
||
if err != nil {
|
||
panic(sys_error.New(fmt.Sprintf("IBP开关操作失败,%s", err.Error()), err))
|
||
}
|
||
c.JSON(http.StatusOK, "ok")
|
||
}
|
||
|
||
// PSL按钮操作
|
||
//
|
||
// @Summary PSL操作
|
||
//
|
||
// @Security JwtAuth
|
||
//
|
||
// @Description PSL操作
|
||
// @Tags ATS测试仿真Api
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param Authorization header string true "JWT Token"
|
||
// @Param PslOperationReqDto body dto.PslOperationReqDto true "PSL操作"
|
||
//
|
||
// @Success 200 {object} string
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/psl/operation [post]
|
||
func pslBtnOperation(c *gin.Context) {
|
||
req := &dto.PslOperationReqDto{}
|
||
if err := c.ShouldBind(&req); err != nil {
|
||
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
|
||
}
|
||
simulation := checkDeviceDataAndReturn(req.SimulationId)
|
||
slog.Info("传入状态参数", req)
|
||
memory.ChangePSLButtonState(simulation, req.MapId, req.GateBoxId, req.ButtonCode, req.Down)
|
||
c.JSON(http.StatusOK, "ok")
|
||
}
|
||
|
||
// 屏蔽门操作
|
||
//
|
||
// @Summary 屏蔽门操作
|
||
//
|
||
// @Security JwtAuth
|
||
//
|
||
// @Description 屏蔽门操作
|
||
// @Tags ATS测试仿真Api
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param Authorization header string true "JWT Token"
|
||
// @Param PsdOperationReq body request_proto.PsdOperationReq true "屏蔽门操作"
|
||
//
|
||
// @Success 200 {object} string
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/psd/operation [post]
|
||
func psdOperation(c *gin.Context) {
|
||
req := &request_proto.PsdOperationReq{}
|
||
if err := c.ShouldBind(&req); err != nil {
|
||
panic(dto.ErrorDto{Code: dto.ArgumentParseError, Message: err.Error()})
|
||
}
|
||
simulation := checkDeviceDataAndReturn(req.SimulationId)
|
||
slog.Info("传入状态参数", req)
|
||
if err := memory.HandlePsdOperation(simulation, req); err != nil {
|
||
panic(sys_error.New(err.Error(), err))
|
||
}
|
||
c.JSON(http.StatusOK, "ok")
|
||
}
|
||
|
||
// 获取仿真地图的公里标范围
|
||
//
|
||
// @Summary 获取仿真地图的公里标范围
|
||
//
|
||
// @Security JwtAuth
|
||
//
|
||
// @Description 获取仿真地图的公里标范围
|
||
// @Tags ATS测试仿真Api
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param Authorization header string true "JWT Token"
|
||
//
|
||
// @Success 200 {object} string
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/:id/getMapKilometerRange [get]
|
||
func getMapKilometerRange(c *gin.Context) {
|
||
id, exist := c.Params.Get("id")
|
||
if !exist {
|
||
panic(sys_error.New("缺少仿真编号"))
|
||
}
|
||
simulation := checkDeviceDataAndReturn(id)
|
||
c.JSON(http.StatusOK, simulation.Repo.GetCoordinateInfo())
|
||
}
|
||
|
||
// 获取ATS测试-操作继电器
|
||
//
|
||
// @Summary 获取ATS测试-操作继电器
|
||
//
|
||
// @Security JwtAuth
|
||
//
|
||
// @Description ATS测试-操作继电器
|
||
// @Tags ATS测试仿真Api
|
||
// @Accept json
|
||
// @Produce json
|
||
// @Param Authorization header string true "JWT Token"
|
||
// @Param RelayOperationReqDto body dto.RelayOperationReqDto true "ATS测试仿真-操作继电器"
|
||
//
|
||
// @Success 200 {object} string
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/relay/operation [post]
|
||
func relayOperation(c *gin.Context) {
|
||
req := &request_proto.RelayOperationReq{}
|
||
if err := c.ShouldBind(&req); err != nil {
|
||
panic(sys_error.New("继电器操作失败,请求参数异常", err))
|
||
}
|
||
simulation := checkDeviceDataAndReturn(req.SimulationId)
|
||
slog.Info("传入状态参数", "param", req)
|
||
err := memory.HandleRelayOperation(simulation, req)
|
||
if err != nil {
|
||
panic(sys_error.New(fmt.Sprintf("继电器操作失败,%s", err.Error()), err))
|
||
}
|
||
c.JSON(http.StatusOK, "ok")
|
||
}
|
||
|
||
// 应答器移位
|
||
//
|
||
// @Summary 应答器移位
|
||
//
|
||
// @Security JwtAuth
|
||
//
|
||
// @Description 应答器移位
|
||
// @Tags ATS测试仿真Api
|
||
// @Accept json
|
||
// @Param Authorization header string true "JWT Token"
|
||
// @Param BaliseMoveReqDto body dto.BaliseMoveReqDto true "应答器移位"
|
||
//
|
||
// @Success 200 {object} string
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/balise/position/modify [put]
|
||
func balisePositionModify(c *gin.Context) {
|
||
req := &dto.BaliseMoveReqDto{}
|
||
if err := c.ShouldBind(&req); err != nil {
|
||
panic(sys_error.New("应答器移位操作失败,请求参数异常", err))
|
||
}
|
||
simulation := checkDeviceDataAndReturn(req.SimulationId)
|
||
slog.Info("传入状态参数", req)
|
||
var err *sys_error.BusinessError = memory.BalisePositionModify(simulation, req)
|
||
if err != nil {
|
||
panic(err)
|
||
}
|
||
c.JSON(http.StatusOK, "ok")
|
||
}
|
||
|
||
// 应答器复位
|
||
//
|
||
// @Summary 应答器复位
|
||
//
|
||
// @Security JwtAuth
|
||
//
|
||
// @Description 应答器复位
|
||
// @Tags ATS测试仿真Api
|
||
// @Accept json
|
||
// @Param Authorization header string true "JWT Token"
|
||
// @Param BaliseReqDto body dto.BaliseReqDto true "应答器复位"
|
||
//
|
||
// @Success 200 {object} string
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/balise/position/reset [put]
|
||
func transponderPositionReset(c *gin.Context) {
|
||
req := &dto.BaliseReqDto{}
|
||
if err := c.ShouldBind(&req); err != nil {
|
||
panic(sys_error.New("应答器复位操作失败,请求参数异常", err))
|
||
}
|
||
simulation := checkDeviceDataAndReturn(req.SimulationId)
|
||
slog.Info("传入状态参数", req)
|
||
err := memory.BalisePositionReset(simulation, req)
|
||
if err != nil {
|
||
panic(sys_error.New(fmt.Sprintf("应答器复位操作失败,%s", err.Error()), err))
|
||
}
|
||
c.JSON(http.StatusOK, "ok")
|
||
}
|
||
|
||
// 修改应答器报文
|
||
//
|
||
// @Summary 修改应答器报文
|
||
//
|
||
// @Security JwtAuth
|
||
//
|
||
// @Description 修改应答器报文
|
||
// @Tags ATS测试仿真Api
|
||
// @Accept json
|
||
// @Param Authorization header string true "JWT Token"
|
||
// @Param BaliseModifyTelegramReqDto body dto.BaliseModifyTelegramReqDto true "修改应答器报文"
|
||
//
|
||
// @Success 200 {object} string
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/balise/telegram/modify [put]
|
||
func baliseTelegramModify(c *gin.Context) {
|
||
req := &dto.BaliseModifyTelegramReqDto{}
|
||
if err := c.ShouldBind(&req); err != nil {
|
||
panic(sys_error.New("应答器修改报文操作失败,请求参数异常", err))
|
||
}
|
||
simulation := checkDeviceDataAndReturn(req.SimulationId)
|
||
slog.Info("传入状态参数", req)
|
||
err := memory.BaliseTelegramModify(simulation, req)
|
||
if err != nil {
|
||
panic(sys_error.New(fmt.Sprintf("应答器修改报文操作失败,%s", err.Error()), err))
|
||
}
|
||
c.JSON(http.StatusOK, "ok")
|
||
}
|
||
|
||
// 重置应答器报文
|
||
//
|
||
// @Summary 重置应答器报文
|
||
//
|
||
// @Security JwtAuth
|
||
//
|
||
// @Description 重置应答器报文
|
||
// @Tags ATS测试仿真Api
|
||
// @Accept json
|
||
// @Param Authorization header string true "JWT Token"
|
||
// @Param BaliseReqDto body dto.BaliseReqDto true "重置应答器报文"
|
||
//
|
||
// @Success 200 {object} string
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/balise/telegram/reset [put]
|
||
func baliseTelegramReset(c *gin.Context) {
|
||
req := &dto.BaliseReqDto{}
|
||
if err := c.ShouldBind(&req); err != nil {
|
||
panic(sys_error.New("应答器重置报文操作失败,请求参数异常", err))
|
||
}
|
||
simulation := checkDeviceDataAndReturn(req.SimulationId)
|
||
slog.Info("传入状态参数", req)
|
||
err := memory.BaliseTelegramReset(simulation, req)
|
||
if err != nil {
|
||
panic(sys_error.New(fmt.Sprintf("应答器重置报文操作失败,%s", err.Error()), err))
|
||
}
|
||
c.JSON(http.StatusOK, "ok")
|
||
}
|
||
|
||
// 重置应答器状态
|
||
//
|
||
// @Summary 重置应答器状态
|
||
//
|
||
// @Security JwtAuth
|
||
//
|
||
// @Description 重置应答器状态
|
||
// @Tags ATS测试仿真Api
|
||
// @Accept json
|
||
// @Param Authorization header string true "JWT Token"
|
||
// @Param simulationId query string true "重置应答器状态"
|
||
//
|
||
// @Success 200 {object} string
|
||
// @Failure 500 {object} dto.ErrorDto
|
||
// @Router /api/v1/simulation/balise/reset [put]
|
||
func baliseReset(c *gin.Context) {
|
||
//req := &dto.BaliseReqDto{}
|
||
//if err := c.ShouldBind(&req); err != nil {
|
||
// panic(sys_error.New("应答器状态重置操作失败,请求参数异常", err))
|
||
//}
|
||
simulationId := c.Query("simulationId")
|
||
simulation := checkDeviceDataAndReturn(simulationId)
|
||
err := memory.BaliseReset(simulation)
|
||
if err != nil {
|
||
panic(sys_error.New(fmt.Sprintf("应答器状态重置操作失败,%s", err.Error()), err))
|
||
}
|
||
c.JSON(http.StatusOK, "ok")
|
||
}
|
||
|
||
// 获取仿真设备数据并返回
|
||
func checkDeviceDataAndReturn(simId string) *memory.VerifySimulation {
|
||
deviceMemory := ts.FindSimulation(simId)
|
||
if deviceMemory == nil {
|
||
panic(sys_error.New(fmt.Sprintf("仿真[%s]不存在", simId)))
|
||
}
|
||
return deviceMemory
|
||
}
|
||
|
||
// 获取列车主键
|
||
func getAddTrainPrimaryKey(simulation *memory.VerifySimulation) int {
|
||
trainMap := &simulation.Memory.Status.TrainStateMap
|
||
// 获取列车ID
|
||
i := 1
|
||
for {
|
||
_, ok := trainMap.Load(strconv.Itoa(i))
|
||
if !ok {
|
||
break
|
||
}
|
||
i++
|
||
}
|
||
return i
|
||
}
|