This commit is contained in:
xzb 2023-11-01 11:08:47 +08:00
commit 443eb8c8eb
6 changed files with 192 additions and 19 deletions

View File

@ -2,10 +2,12 @@ package api
import ( import (
"net/http" "net/http"
"reflect"
"strconv" "strconv"
jwt "github.com/appleboy/gin-jwt/v2" jwt "github.com/appleboy/gin-jwt/v2"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"joylink.club/bj-rtsts-server/config"
"joylink.club/bj-rtsts-server/dto" "joylink.club/bj-rtsts-server/dto"
"joylink.club/bj-rtsts-server/middleware" "joylink.club/bj-rtsts-server/middleware"
"joylink.club/bj-rtsts-server/service" "joylink.club/bj-rtsts-server/service"
@ -20,6 +22,7 @@ func InitProjectRunConfigRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWT
authed.GET("/:id", queryProjectRunConfig) authed.GET("/:id", queryProjectRunConfig)
authed.PUT("/:id", updateProjectRunConfig) authed.PUT("/:id", updateProjectRunConfig)
authed.DELETE("/:id", deleteProjectRunConfig) authed.DELETE("/:id", deleteProjectRunConfig)
authed.GET("/description", getRunCofigDescription)
} }
// 分页查询项目运行环境配置信息 // 分页查询项目运行环境配置信息
@ -169,3 +172,52 @@ func deleteProjectRunConfig(c *gin.Context) {
service.DeleteProjectRunConfigById(int32(id)) service.DeleteProjectRunConfigById(int32(id))
c.JSON(http.StatusOK, true) 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 { type ThridPartyConfig struct {
Id int32 `json:"id"` Id int32 `json:"id"`
Dynamics DynamicsConfig `json:"dynamics"` Dynamics DynamicsConfig `json:"dynamics" description:"动力学配置"`
Vobc VobcConfig `json:"vobc"` Vobc VobcConfig `json:"vobc" description:"半实物配置"`
Interlocks []InterlockConfig `json:"interlock"` Interlocks []InterlockConfig `json:"interlock" description:"联锁配置"`
} }
type DynamicsConfig struct { type DynamicsConfig struct {
Ip string `json:"ip"` Ip string `json:"ip" description:"IP配置"`
UdpLocalPort int `json:"udpLocalPort"` UdpLocalPort int `json:"udpLocalPort" description:"本机监听接收端口"`
UdpRemotePort int `json:"udpRemotePort"` UdpRemotePort int `json:"udpRemotePort" description:"远端接收道岔信息端口"`
UdpRemoteTrainPort int `json:"udpRemoteTrainPort"` UdpRemoteTrainPort int `json:"udpRemoteTrainPort" description:"远端接收列车信息端口"`
HttpPort int `json:"httpPort"` HttpPort int `json:"httpPort" description:"http服务端口"`
Open bool `json:"open"` Open bool `json:"open" description:"是否开启"`
} }
type VobcConfig struct { type VobcConfig struct {
Ip string `json:"ip"` Ip string `json:"ip" description:"IP配置"`
LocalPort int `json:"localPort"` LocalPort int `json:"localPort" description:"本机监听接收端口"`
RemotePort int `json:"remotePort"` RemotePort int `json:"remotePort" description:"远端接收列车信息端口"`
Open bool `json:"open"` Open bool `json:"open" description:"是否开启"`
} }
type InterlockConfig struct { type InterlockConfig struct {
Ip string `json:"ip"` Ip string `json:"ip" description:"IP配置"`
LocalPort int `json:"localPort"` LocalPort int `json:"localPort" description:"本机监听接收端口"`
RemotePort int `json:"remotePort"` RemotePort int `json:"remotePort" description:"远端接收采集信息端口"`
Open bool `json:"open"` Open bool `json:"open" description:"是否开启"`
Code string `json:"code"` Code string `json:"code" description:"所属集中站"`
} }
var Config AppConfig var Config AppConfig

View File

@ -1,4 +1,5 @@
// Package docs Code generated by swaggo/swag. DO NOT EDIT // Code generated by swaggo/swag. DO NOT EDIT.
package docs package docs
import "github.com/swaggo/swag" 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": { "/api/v1/runconfig/list": {
"get": { "get": {
"security": [ "security": [

View File

@ -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": { "/api/v1/runconfig/list": {
"get": { "get": {
"security": [ "security": [

View File

@ -2627,6 +2627,33 @@ paths:
summary: 修改项目运行环境信息 summary: 修改项目运行环境信息
tags: tags:
- 项目运行环境配置Api - 项目运行环境配置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: /api/v1/runconfig/list:
get: get:
consumes: consumes:

View File

@ -23,6 +23,13 @@ type ProjectRunConfigDto struct {
UpdateAt JsonTime `json:"updateAt" time_format:"2006-01-02 15:04:05"` 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 { func ConvertToRunConfigDto(gi *model.ProjectRunConfig) *ProjectRunConfigDto {
return &ProjectRunConfigDto{ return &ProjectRunConfigDto{
Id: gi.ID, Id: gi.ID,