【增加获取运行环境结构说明接口】

This commit is contained in:
weizhihong 2023-10-31 18:08:17 +08:00
parent 4e110e94fe
commit ec3eb2f7d0
6 changed files with 239 additions and 159 deletions

View File

@ -2,10 +2,12 @@ package api
import (
"net/http"
"reflect"
"strconv"
jwt "github.com/appleboy/gin-jwt/v2"
"github.com/gin-gonic/gin"
"joylink.club/bj-rtsts-server/config"
"joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/middleware"
"joylink.club/bj-rtsts-server/service"
@ -20,6 +22,7 @@ func InitProjectRunConfigRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWT
authed.GET("/:id", queryProjectRunConfig)
authed.PUT("/:id", updateProjectRunConfig)
authed.DELETE("/:id", deleteProjectRunConfig)
authed.GET("/description", getRunCofigDescription)
}
// 分页查询项目运行环境配置信息
@ -169,3 +172,52 @@ func deleteProjectRunConfig(c *gin.Context) {
service.DeleteProjectRunConfigById(int32(id))
c.JSON(http.StatusOK, true)
}
// 获取项目运行环境信息结构说明
//
// @Summary 获取项目运行环境信息结构说明
//
// @Security JwtAuth
//
// @Description 获取项目运行环境信息结构说明
// @Tags 项目运行环境配置Api
// @Accept json
// @Produce json
// @Success 200 {object} nil
// @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/runconfig/description [get]
func getRunCofigDescription(c *gin.Context) {
c.JSON(http.StatusOK, parseRunCofigStruct(&config.ThridPartyConfig{}))
}
// 解析环境配置结构
func parseRunCofigStruct(m interface{}) []*dto.RunConfigDescription {
var cs []*dto.RunConfigDescription
t := reflect.TypeOf(m).Elem()
for i := 0; i < t.NumField(); i++ {
field := t.Field(i)
if field.Tag.Get("description") == "" {
continue
}
c := &dto.RunConfigDescription{
FieldName: field.Tag.Get("json"),
Description: field.Tag.Get("description"),
}
k := field.Type.Kind()
switch k {
case reflect.Struct:
c.ItemTypeFields = parseRunCofigStruct(reflect.New(field.Type).Interface())
c.Type = "map"
case reflect.Slice:
e := field.Type.Elem()
c.ItemTypeFields = parseRunCofigStruct(reflect.New(e).Interface())
c.Type = "array"
default:
c.Type = k.String()
}
cs = append(cs, c)
}
return cs
}

View File

@ -53,30 +53,30 @@ type centrifugo struct {
// 第三方配置结构
type ThridPartyConfig struct {
Id int32 `json:"id"`
Dynamics DynamicsConfig `json:"dynamics"`
Vobc VobcConfig `json:"vobc"`
Interlocks []InterlockConfig `json:"interlock"`
Dynamics DynamicsConfig `json:"dynamics" description:"动力学配置"`
Vobc VobcConfig `json:"vobc" description:"半实物配置"`
Interlocks []InterlockConfig `json:"interlock" description:"联锁配置"`
}
type DynamicsConfig struct {
Ip string `json:"ip"`
UdpLocalPort int `json:"udpLocalPort"`
UdpRemotePort int `json:"udpRemotePort"`
UdpRemoteTrainPort int `json:"udpRemoteTrainPort"`
HttpPort int `json:"httpPort"`
Open bool `json:"open"`
Ip string `json:"ip" description:"IP配置"`
UdpLocalPort int `json:"udpLocalPort" description:"本机监听接收端口"`
UdpRemotePort int `json:"udpRemotePort" description:"远端接收道岔信息端口"`
UdpRemoteTrainPort int `json:"udpRemoteTrainPort" description:"远端接收列车信息端口"`
HttpPort int `json:"httpPort" description:"http服务端口"`
Open bool `json:"open" description:"是否开启"`
}
type VobcConfig struct {
Ip string `json:"ip"`
LocalPort int `json:"localPort"`
RemotePort int `json:"remotePort"`
Open bool `json:"open"`
Ip string `json:"ip" description:"IP配置"`
LocalPort int `json:"localPort" description:"本机监听接收端口"`
RemotePort int `json:"remotePort" description:"远端接收列车信息端口"`
Open bool `json:"open" description:"是否开启"`
}
type InterlockConfig struct {
Ip string `json:"ip"`
LocalPort int `json:"localPort"`
RemotePort int `json:"remotePort"`
Open bool `json:"open"`
Code string `json:"code"`
Ip string `json:"ip" description:"IP配置"`
LocalPort int `json:"localPort" description:"本机监听接收端口"`
RemotePort int `json:"remotePort" description:"远端接收采集信息端口"`
Open bool `json:"open" description:"是否开启"`
Code string `json:"code" description:"所属集中站"`
}
var Config AppConfig

View File

@ -2758,7 +2758,8 @@ const docTemplate = `{
{
"type": "string",
"name": "config",
"in": "query"
"in": "query",
"required": true
},
{
"type": "string",
@ -2773,7 +2774,8 @@ const docTemplate = `{
{
"type": "string",
"name": "name",
"in": "query"
"in": "query",
"required": true
}
],
"responses": {
@ -2801,6 +2803,49 @@ const docTemplate = `{
}
}
},
"/api/v1/runconfig/description": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "获取项目运行环境信息结构说明",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"项目运行环境配置Api"
],
"summary": "获取项目运行环境信息结构说明",
"responses": {
"200": {
"description": "OK"
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/runconfig/list": {
"get": {
"security": [
@ -3387,49 +3432,6 @@ const docTemplate = `{
}
}
},
"/api/v1/simulation/getDataChannelName": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "获取仿真信息更新通道名称",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ATS测试仿真Api"
],
"summary": "获取仿真信息更新通道名称",
"parameters": [
{
"type": "string",
"description": "JWT Token",
"name": "Authorization",
"in": "header",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/simulation/ibp/btn/operation": {
"post": {
"security": [
@ -5682,6 +5684,10 @@ const docTemplate = `{
"projectId": {
"description": "项目id",
"type": "integer"
},
"runConfigId": {
"description": "运行环境ID",
"type": "integer"
}
}
},
@ -5703,6 +5709,10 @@ const docTemplate = `{
"description": "项目ID",
"type": "integer"
},
"runConfigId": {
"description": "运行环境ID",
"type": "integer"
},
"simulationId": {
"description": "仿真id",
"type": "string"
@ -5724,6 +5734,10 @@ const docTemplate = `{
"projectId": {
"type": "integer"
},
"runConfigId": {
"description": "运行环境ID",
"type": "integer"
},
"simulationId": {
"type": "string"
}
@ -6052,21 +6066,15 @@ const docTemplate = `{
"type": "integer",
"enum": [
0,
1,
2,
3
1
],
"x-enum-comments": {
"Section_Drst": "设置计轴直接复位",
"Section_Pdrst": "设置计轴预复位",
"Section_TrainIn": "设置计轴区段内有车轴",
"Section_TrainOut": "设置计轴区段内没有车轴"
"Section_Pdrst": "设置计轴预复位"
},
"x-enum-varnames": [
"Section_Drst",
"Section_Pdrst",
"Section_TrainIn",
"Section_TrainOut"
"Section_Pdrst"
]
},
"request_proto.Signal_Operation": {

View File

@ -2751,7 +2751,8 @@
{
"type": "string",
"name": "config",
"in": "query"
"in": "query",
"required": true
},
{
"type": "string",
@ -2766,7 +2767,8 @@
{
"type": "string",
"name": "name",
"in": "query"
"in": "query",
"required": true
}
],
"responses": {
@ -2794,6 +2796,49 @@
}
}
},
"/api/v1/runconfig/description": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "获取项目运行环境信息结构说明",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"项目运行环境配置Api"
],
"summary": "获取项目运行环境信息结构说明",
"responses": {
"200": {
"description": "OK"
},
"401": {
"description": "Unauthorized",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/runconfig/list": {
"get": {
"security": [
@ -3380,49 +3425,6 @@
}
}
},
"/api/v1/simulation/getDataChannelName": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "获取仿真信息更新通道名称",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ATS测试仿真Api"
],
"summary": "获取仿真信息更新通道名称",
"parameters": [
{
"type": "string",
"description": "JWT Token",
"name": "Authorization",
"in": "header",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/simulation/ibp/btn/operation": {
"post": {
"security": [
@ -5675,6 +5677,10 @@
"projectId": {
"description": "项目id",
"type": "integer"
},
"runConfigId": {
"description": "运行环境ID",
"type": "integer"
}
}
},
@ -5696,6 +5702,10 @@
"description": "项目ID",
"type": "integer"
},
"runConfigId": {
"description": "运行环境ID",
"type": "integer"
},
"simulationId": {
"description": "仿真id",
"type": "string"
@ -5717,6 +5727,10 @@
"projectId": {
"type": "integer"
},
"runConfigId": {
"description": "运行环境ID",
"type": "integer"
},
"simulationId": {
"type": "string"
}
@ -6045,21 +6059,15 @@
"type": "integer",
"enum": [
0,
1,
2,
3
1
],
"x-enum-comments": {
"Section_Drst": "设置计轴直接复位",
"Section_Pdrst": "设置计轴预复位",
"Section_TrainIn": "设置计轴区段内有车轴",
"Section_TrainOut": "设置计轴区段内没有车轴"
"Section_Pdrst": "设置计轴预复位"
},
"x-enum-varnames": [
"Section_Drst",
"Section_Pdrst",
"Section_TrainIn",
"Section_TrainOut"
"Section_Pdrst"
]
},
"request_proto.Signal_Operation": {

View File

@ -333,6 +333,9 @@ definitions:
projectId:
description: 项目id
type: integer
runConfigId:
description: 运行环境ID
type: integer
type: object
dto.SimulationCreateRspDto:
properties:
@ -347,6 +350,9 @@ definitions:
projectId:
description: 项目ID
type: integer
runConfigId:
description: 运行环境ID
type: integer
simulationId:
description: 仿真id
type: string
@ -361,6 +367,9 @@ definitions:
type: array
projectId:
type: integer
runConfigId:
description: 运行环境ID
type: integer
simulationId:
type: string
type: object
@ -596,19 +605,13 @@ definitions:
enum:
- 0
- 1
- 2
- 3
type: integer
x-enum-comments:
Section_Drst: 设置计轴直接复位
Section_Pdrst: 设置计轴预复位
Section_TrainIn: 设置计轴区段内有车轴
Section_TrainOut: 设置计轴区段内没有车轴
x-enum-varnames:
- Section_Drst
- Section_Pdrst
- Section_TrainIn
- Section_TrainOut
request_proto.Signal_Operation:
enum:
- 0
@ -2464,6 +2467,7 @@ paths:
parameters:
- in: query
name: config
required: true
type: string
- in: query
name: description
@ -2473,6 +2477,7 @@ paths:
type: integer
- in: query
name: name
required: true
type: string
produces:
- application/json
@ -2604,6 +2609,33 @@ paths:
summary: 修改项目运行环境信息
tags:
- 项目运行环境配置Api
/api/v1/runconfig/description:
get:
consumes:
- application/json
description: 获取项目运行环境信息结构说明
produces:
- application/json
responses:
"200":
description: OK
"401":
description: Unauthorized
schema:
$ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 获取项目运行环境信息结构说明
tags:
- 项目运行环境配置Api
/api/v1/runconfig/list:
get:
consumes:
@ -2869,33 +2901,6 @@ paths:
summary: ATS测试-ESB按钮操作
tags:
- ATS测试仿真Api
/api/v1/simulation/getDataChannelName:
get:
consumes:
- application/json
description: 获取仿真信息更新通道名称
parameters:
- description: JWT Token
in: header
name: Authorization
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
type: string
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 获取仿真信息更新通道名称
tags:
- ATS测试仿真Api
/api/v1/simulation/ibp/btn/operation:
post:
consumes:

View File

@ -23,6 +23,13 @@ type ProjectRunConfigDto struct {
UpdateAt JsonTime `json:"updateAt" time_format:"2006-01-02 15:04:05"`
}
type RunConfigDescription struct {
FieldName string `json:"fieldName" form:"fieldName"`
Description string `json:"description" form:"description"`
Type string `json:"type" form:"type"`
ItemTypeFields []*RunConfigDescription `json:"itemTypeFields" form:"itemTypeFields"`
}
func ConvertToRunConfigDto(gi *model.ProjectRunConfig) *ProjectRunConfigDto {
return &ProjectRunConfigDto{
Id: gi.ID,