diff --git a/api/projectRunConfig.go b/api/projectRunConfig.go index dfb0f79..4ca0cc9 100644 --- a/api/projectRunConfig.go +++ b/api/projectRunConfig.go @@ -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 +} diff --git a/config/config.go b/config/config.go index 42f32c7..b3748cd 100644 --- a/config/config.go +++ b/config/config.go @@ -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 diff --git a/docs/docs.go b/docs/docs.go index bcea4a8..f768548 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1,4 +1,5 @@ -// Package docs Code generated by swaggo/swag. DO NOT EDIT +// Code generated by swaggo/swag. DO NOT EDIT. + package docs import "github.com/swaggo/swag" @@ -2802,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": [ diff --git a/docs/swagger.json b/docs/swagger.json index b46be8b..2f75dcb 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -2796,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": [ diff --git a/docs/swagger.yaml b/docs/swagger.yaml index fe844f0..ae3b795 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -2627,6 +2627,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: diff --git a/dto/projectRunConfig.go b/dto/projectRunConfig.go index e325e8c..fa59f95 100644 --- a/dto/projectRunConfig.go +++ b/dto/projectRunConfig.go @@ -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,