增加错误码常量;增加自定义时间及序列化反序列逻辑

This commit is contained in:
joylink_zhangsai 2023-07-31 10:15:02 +08:00
parent 82fd662d33
commit d76dcbac18
8 changed files with 92 additions and 1012 deletions

View File

@ -35,7 +35,6 @@ func InitPublishedGiRouter(api *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddl
// @Param pagePublishedGiReqDto query dto.PublishedGiReqDto true "分页查询参数" // @Param pagePublishedGiReqDto query dto.PublishedGiReqDto true "分页查询参数"
// @Success 200 {object} dto.PageDto // @Success 200 {object} dto.PageDto
// @Failure 401 {object} dto.ErrorDto // @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto // @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/publishedGi/paging [get] // @Router /api/v1/publishedGi/paging [get]
func pageQueryPublishedGi(c *gin.Context) { func pageQueryPublishedGi(c *gin.Context) {
@ -68,7 +67,6 @@ func pageQueryPublishedGi(c *gin.Context) {
// @Param pagePublishedGiReqDto query dto.PublishedGiReqDto true "查询参数" // @Param pagePublishedGiReqDto query dto.PublishedGiReqDto true "查询参数"
// @Success 200 {object} []model.PublishedGi // @Success 200 {object} []model.PublishedGi
// @Failure 401 {object} dto.ErrorDto // @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto // @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/publishedGi/list [get] // @Router /api/v1/publishedGi/list [get]
func listQueryPublishedGi(c *gin.Context) { func listQueryPublishedGi(c *gin.Context) {
@ -86,34 +84,6 @@ func listQueryPublishedGi(c *gin.Context) {
c.JSON(http.StatusOK, list) c.JSON(http.StatusOK, list)
} }
// 从草稿发布数据
//
// @Summary 从草稿发布数据
//
// @Security JwtAuth
//
// @Description
// @Tags 发布的图形数据Api
// @Accept json
// @Produce json
// @Param Authorization header string true "JWT Token"
// @Param PublishReqDto query dto.PublishReqDto true "查询参数"
// @Success 200 {object} nil
// @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/publishedGi/publish [post]
func publishFromDraft(c *gin.Context) {
user, _ := c.Get(middleware.IdentityKey)
zap.S().Debug("发布图形数据", user)
req := dto.PublishReqDto{}
if err := c.ShouldBind(&req); err != nil {
zap.S().Warn("发布图形数据参数绑定错误", err)
}
zap.S().Debug("发布图形数据请求参数", req)
service.PublishFormDraft(&req, user.(*model.User))
}
// id 查询发布的图形数据 // id 查询发布的图形数据
// //
// @Summary id查询发布的图形数据 // @Summary id查询发布的图形数据
@ -128,7 +98,6 @@ func publishFromDraft(c *gin.Context) {
// @Param id path int true "id" // @Param id path int true "id"
// @Success 200 {object} model.PublishedGi // @Success 200 {object} model.PublishedGi
// @Failure 401 {object} dto.ErrorDto // @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto // @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/publishedGi/{id} [get] // @Router /api/v1/publishedGi/{id} [get]
func getPublishedGiById(c *gin.Context) { func getPublishedGiById(c *gin.Context) {
@ -147,9 +116,36 @@ func getPublishedGiById(c *gin.Context) {
c.JSON(http.StatusOK, entity) c.JSON(http.StatusOK, entity)
} }
// id 查询发布的图形数据 // 从草稿发布数据
// //
// @Summary id查询发布的图形数据 // @Summary 从草稿发布数据
//
// @Security JwtAuth
//
// @Description
// @Tags 发布的图形数据Api
// @Accept json
// @Produce json
// @Param Authorization header string true "JWT Token"
// @Param PublishReqDto query dto.PublishReqDto true "查询参数"
// @Success 200
// @Failure 401 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/publishedGi/publish [post]
func publishFromDraft(c *gin.Context) {
user, _ := c.Get(middleware.IdentityKey)
zap.S().Debug("发布图形数据", user)
req := dto.PublishReqDto{}
if err := c.ShouldBind(&req); err != nil {
zap.S().Warn("发布图形数据参数绑定错误", err)
}
zap.S().Debug("发布图形数据请求参数", req)
service.PublishFormDraft(&req, user.(*model.User))
}
// id 删除发布的图形数据
//
// @Summary id删除发布的图形数据
// //
// @Security JwtAuth // @Security JwtAuth
// //
@ -161,7 +157,6 @@ func getPublishedGiById(c *gin.Context) {
// @Param id path int true "id" // @Param id path int true "id"
// @Success 200 {object} nil // @Success 200 {object} nil
// @Failure 401 {object} dto.ErrorDto // @Failure 401 {object} dto.ErrorDto
// @Failure 404 {object} dto.ErrorDto
// @Failure 500 {object} dto.ErrorDto // @Failure 500 {object} dto.ErrorDto
// @Router /api/v1/publishedGi/{id} [delete] // @Router /api/v1/publishedGi/{id} [delete]
func deletePublishedGiById(c *gin.Context) { func deletePublishedGiById(c *gin.Context) {

View File

@ -458,12 +458,6 @@ const docTemplate = `{
"$ref": "#/definitions/dto.ErrorDto" "$ref": "#/definitions/dto.ErrorDto"
} }
}, },
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
@ -534,12 +528,6 @@ const docTemplate = `{
"$ref": "#/definitions/dto.ErrorDto" "$ref": "#/definitions/dto.ErrorDto"
} }
}, },
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
@ -585,12 +573,6 @@ const docTemplate = `{
"description": "发布后的名称", "description": "发布后的名称",
"name": "name", "name": "name",
"in": "query" "in": "query"
},
{
"type": "boolean",
"description": "是否覆盖同名数据",
"name": "overwrite",
"in": "query"
} }
], ],
"responses": { "responses": {
@ -603,12 +585,6 @@ const docTemplate = `{
"$ref": "#/definitions/dto.ErrorDto" "$ref": "#/definitions/dto.ErrorDto"
} }
}, },
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
@ -665,12 +641,6 @@ const docTemplate = `{
"$ref": "#/definitions/dto.ErrorDto" "$ref": "#/definitions/dto.ErrorDto"
} }
}, },
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
@ -695,7 +665,7 @@ const docTemplate = `{
"tags": [ "tags": [
"发布的图形数据Api" "发布的图形数据Api"
], ],
"summary": "id查询发布的图形数据", "summary": "id删除发布的图形数据",
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
@ -722,64 +692,6 @@ const docTemplate = `{
"$ref": "#/definitions/dto.ErrorDto" "$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/simulation/check/data": {
"post": {
"security": [
{
"JwtAuth": []
}
],
"description": "ATS测试仿真-添加列车",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ATS测试仿真Api"
],
"summary": "ATS测试仿真地图数据校验",
"parameters": [
{
"type": "string",
"description": "JWT Token",
"name": "Authorization",
"in": "header",
"required": true
},
{
"description": "ATS测试仿真-地图数据",
"name": "RemoveTrainDto",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.CheckMapDataReqDto"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dto.CheckMapDataRspDto"
}
},
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
@ -841,104 +753,6 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/simulation/list": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "ATS测试仿真-添加列车",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ATS测试仿真Api"
],
"summary": "获取ATS测试系统所有仿真实例的基本信息",
"parameters": [
{
"type": "string",
"description": "JWT Token",
"name": "Authorization",
"in": "header",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/dto.SimulationInfoRepDto"
}
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/simulation/switch/operation": {
"post": {
"security": [
{
"JwtAuth": []
}
],
"description": "ATS测试仿真-添加列车",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ATS测试仿真Api"
],
"summary": "获取ATS测试-操作道岔",
"parameters": [
{
"type": "string",
"description": "JWT Token",
"name": "Authorization",
"in": "header",
"required": true
},
{
"description": "ATS测试仿真-操作道岔",
"name": "RemoveTrainDto",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.SwitchOperationReqDto"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/simulation/train/add": { "/api/v1/simulation/train/add": {
"post": { "post": {
"security": [ "security": [
@ -991,108 +805,6 @@ const docTemplate = `{
} }
} }
}, },
"/api/v1/simulation/train/destroy/{id}": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "ATS测试仿真-添加列车",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ATS测试仿真Api"
],
"summary": "ATS仿真销毁",
"parameters": [
{
"type": "string",
"description": "JWT Token",
"name": "Authorization",
"in": "header",
"required": true
},
{
"type": "integer",
"description": "仿真id",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/simulation/train/remove": {
"post": {
"security": [
{
"JwtAuth": []
}
],
"description": "ATS测试仿真-移除列车",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ATS测试仿真Api"
],
"summary": "ATS测试仿真-移除列车",
"parameters": [
{
"type": "string",
"description": "JWT Token",
"name": "Authorization",
"in": "header",
"required": true
},
{
"description": "ATS测试仿真-移除列车",
"name": "RemoveTrainDto",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.RemoveTrainDto"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/user/current": { "/api/v1/user/current": {
"get": { "get": {
"description": "获取当前登录用户信息", "description": "获取当前登录用户信息",
@ -1323,34 +1035,6 @@ const docTemplate = `{
} }
} }
}, },
"dto.CheckMapDataReqDto": {
"type": "object",
"required": [
"data"
],
"properties": {
"data": {
"type": "array",
"items": {
"type": "integer"
}
}
}
},
"dto.CheckMapDataRspDto": {
"type": "object",
"properties": {
"errors": {
"type": "array",
"items": {
"type": "string"
}
},
"success": {
"type": "boolean"
}
}
},
"dto.ErrorDto": { "dto.ErrorDto": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -1446,19 +1130,6 @@ const docTemplate = `{
} }
} }
}, },
"dto.RemoveTrainDto": {
"type": "object",
"properties": {
"simulationId": {
"description": "仿真id",
"type": "string"
},
"trainId": {
"description": "新添加的列车的索引",
"type": "string"
}
}
},
"dto.SimulationCreateReqDto": { "dto.SimulationCreateReqDto": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -1481,40 +1152,6 @@ const docTemplate = `{
} }
} }
}, },
"dto.SimulationInfoRepDto": {
"type": "object",
"properties": {
"mapId": {
"type": "string"
},
"simulationId": {
"type": "string"
}
}
},
"dto.SwitchOperationReqDto": {
"type": "object",
"required": [
"simulationId",
"switchIndex",
"turnNormal",
"turnReverse"
],
"properties": {
"simulationId": {
"type": "string"
},
"switchIndex": {
"type": "string"
},
"turnNormal": {
"type": "boolean"
},
"turnReverse": {
"type": "boolean"
}
}
},
"dto.TokenRespDto": { "dto.TokenRespDto": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@ -451,12 +451,6 @@
"$ref": "#/definitions/dto.ErrorDto" "$ref": "#/definitions/dto.ErrorDto"
} }
}, },
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
@ -527,12 +521,6 @@
"$ref": "#/definitions/dto.ErrorDto" "$ref": "#/definitions/dto.ErrorDto"
} }
}, },
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
@ -578,12 +566,6 @@
"description": "发布后的名称", "description": "发布后的名称",
"name": "name", "name": "name",
"in": "query" "in": "query"
},
{
"type": "boolean",
"description": "是否覆盖同名数据",
"name": "overwrite",
"in": "query"
} }
], ],
"responses": { "responses": {
@ -596,12 +578,6 @@
"$ref": "#/definitions/dto.ErrorDto" "$ref": "#/definitions/dto.ErrorDto"
} }
}, },
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
@ -658,12 +634,6 @@
"$ref": "#/definitions/dto.ErrorDto" "$ref": "#/definitions/dto.ErrorDto"
} }
}, },
"404": {
"description": "Not Found",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
},
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
@ -688,7 +658,7 @@
"tags": [ "tags": [
"发布的图形数据Api" "发布的图形数据Api"
], ],
"summary": "id查询发布的图形数据", "summary": "id删除发布的图形数据",
"parameters": [ "parameters": [
{ {
"type": "string", "type": "string",
@ -715,64 +685,6 @@
"$ref": "#/definitions/dto.ErrorDto" "$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/simulation/check/data": {
"post": {
"security": [
{
"JwtAuth": []
}
],
"description": "ATS测试仿真-添加列车",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ATS测试仿真Api"
],
"summary": "ATS测试仿真地图数据校验",
"parameters": [
{
"type": "string",
"description": "JWT Token",
"name": "Authorization",
"in": "header",
"required": true
},
{
"description": "ATS测试仿真-地图数据",
"name": "RemoveTrainDto",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.CheckMapDataReqDto"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/dto.CheckMapDataRspDto"
}
},
"500": { "500": {
"description": "Internal Server Error", "description": "Internal Server Error",
"schema": { "schema": {
@ -834,104 +746,6 @@
} }
} }
}, },
"/api/v1/simulation/list": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "ATS测试仿真-添加列车",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ATS测试仿真Api"
],
"summary": "获取ATS测试系统所有仿真实例的基本信息",
"parameters": [
{
"type": "string",
"description": "JWT Token",
"name": "Authorization",
"in": "header",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "array",
"items": {
"$ref": "#/definitions/dto.SimulationInfoRepDto"
}
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/simulation/switch/operation": {
"post": {
"security": [
{
"JwtAuth": []
}
],
"description": "ATS测试仿真-添加列车",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ATS测试仿真Api"
],
"summary": "获取ATS测试-操作道岔",
"parameters": [
{
"type": "string",
"description": "JWT Token",
"name": "Authorization",
"in": "header",
"required": true
},
{
"description": "ATS测试仿真-操作道岔",
"name": "RemoveTrainDto",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.SwitchOperationReqDto"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/simulation/train/add": { "/api/v1/simulation/train/add": {
"post": { "post": {
"security": [ "security": [
@ -984,108 +798,6 @@
} }
} }
}, },
"/api/v1/simulation/train/destroy/{id}": {
"get": {
"security": [
{
"JwtAuth": []
}
],
"description": "ATS测试仿真-添加列车",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ATS测试仿真Api"
],
"summary": "ATS仿真销毁",
"parameters": [
{
"type": "string",
"description": "JWT Token",
"name": "Authorization",
"in": "header",
"required": true
},
{
"type": "integer",
"description": "仿真id",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/simulation/train/remove": {
"post": {
"security": [
{
"JwtAuth": []
}
],
"description": "ATS测试仿真-移除列车",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"ATS测试仿真Api"
],
"summary": "ATS测试仿真-移除列车",
"parameters": [
{
"type": "string",
"description": "JWT Token",
"name": "Authorization",
"in": "header",
"required": true
},
{
"description": "ATS测试仿真-移除列车",
"name": "RemoveTrainDto",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/dto.RemoveTrainDto"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"type": "string"
}
},
"500": {
"description": "Internal Server Error",
"schema": {
"$ref": "#/definitions/dto.ErrorDto"
}
}
}
}
},
"/api/v1/user/current": { "/api/v1/user/current": {
"get": { "get": {
"description": "获取当前登录用户信息", "description": "获取当前登录用户信息",
@ -1316,34 +1028,6 @@
} }
} }
}, },
"dto.CheckMapDataReqDto": {
"type": "object",
"required": [
"data"
],
"properties": {
"data": {
"type": "array",
"items": {
"type": "integer"
}
}
}
},
"dto.CheckMapDataRspDto": {
"type": "object",
"properties": {
"errors": {
"type": "array",
"items": {
"type": "string"
}
},
"success": {
"type": "boolean"
}
}
},
"dto.ErrorDto": { "dto.ErrorDto": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -1439,19 +1123,6 @@
} }
} }
}, },
"dto.RemoveTrainDto": {
"type": "object",
"properties": {
"simulationId": {
"description": "仿真id",
"type": "string"
},
"trainId": {
"description": "新添加的列车的索引",
"type": "string"
}
}
},
"dto.SimulationCreateReqDto": { "dto.SimulationCreateReqDto": {
"type": "object", "type": "object",
"properties": { "properties": {
@ -1474,40 +1145,6 @@
} }
} }
}, },
"dto.SimulationInfoRepDto": {
"type": "object",
"properties": {
"mapId": {
"type": "string"
},
"simulationId": {
"type": "string"
}
}
},
"dto.SwitchOperationReqDto": {
"type": "object",
"required": [
"simulationId",
"switchIndex",
"turnNormal",
"turnReverse"
],
"properties": {
"simulationId": {
"type": "string"
},
"switchIndex": {
"type": "string"
},
"turnNormal": {
"type": "boolean"
},
"turnReverse": {
"type": "boolean"
}
}
},
"dto.TokenRespDto": { "dto.TokenRespDto": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@ -24,24 +24,6 @@ definitions:
description: 新添加的列车的索引 description: 新添加的列车的索引
type: string type: string
type: object type: object
dto.CheckMapDataReqDto:
properties:
data:
items:
type: integer
type: array
required:
- data
type: object
dto.CheckMapDataRspDto:
properties:
errors:
items:
type: string
type: array
success:
type: boolean
type: object
dto.ErrorDto: dto.ErrorDto:
properties: properties:
code: code:
@ -109,15 +91,6 @@ definitions:
description: 注册时间 description: 注册时间
type: string type: string
type: object type: object
dto.RemoveTrainDto:
properties:
simulationId:
description: 仿真id
type: string
trainId:
description: 新添加的列车的索引
type: string
type: object
dto.SimulationCreateReqDto: dto.SimulationCreateReqDto:
properties: properties:
mapId: mapId:
@ -133,29 +106,6 @@ definitions:
description: 仿真id description: 仿真id
type: string type: string
type: object type: object
dto.SimulationInfoRepDto:
properties:
mapId:
type: string
simulationId:
type: string
type: object
dto.SwitchOperationReqDto:
properties:
simulationId:
type: string
switchIndex:
type: string
turnNormal:
type: boolean
turnReverse:
type: boolean
required:
- simulationId
- switchIndex
- turnNormal
- turnReverse
type: object
dto.TokenRespDto: dto.TokenRespDto:
properties: properties:
code: code:
@ -481,17 +431,13 @@ paths:
description: Unauthorized description: Unauthorized
schema: schema:
$ref: '#/definitions/dto.ErrorDto' $ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
$ref: '#/definitions/dto.ErrorDto' $ref: '#/definitions/dto.ErrorDto'
security: security:
- JwtAuth: [] - JwtAuth: []
summary: id查询发布的图形数据 summary: id删除发布的图形数据
tags: tags:
- 发布的图形数据Api - 发布的图形数据Api
get: get:
@ -520,10 +466,6 @@ paths:
description: Unauthorized description: Unauthorized
schema: schema:
$ref: '#/definitions/dto.ErrorDto' $ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
@ -572,10 +514,6 @@ paths:
description: Unauthorized description: Unauthorized
schema: schema:
$ref: '#/definitions/dto.ErrorDto' $ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
@ -622,10 +560,6 @@ paths:
description: Unauthorized description: Unauthorized
schema: schema:
$ref: '#/definitions/dto.ErrorDto' $ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
@ -653,10 +587,6 @@ paths:
in: query in: query
name: name name: name
type: string type: string
- description: 是否覆盖同名数据
in: query
name: overwrite
type: boolean
produces: produces:
- application/json - application/json
responses: responses:
@ -666,10 +596,6 @@ paths:
description: Unauthorized description: Unauthorized
schema: schema:
$ref: '#/definitions/dto.ErrorDto' $ref: '#/definitions/dto.ErrorDto'
"404":
description: Not Found
schema:
$ref: '#/definitions/dto.ErrorDto'
"500": "500":
description: Internal Server Error description: Internal Server Error
schema: schema:
@ -679,39 +605,6 @@ paths:
summary: 从草稿发布数据 summary: 从草稿发布数据
tags: tags:
- 发布的图形数据Api - 发布的图形数据Api
/api/v1/simulation/check/data:
post:
consumes:
- application/json
description: ATS测试仿真-添加列车
parameters:
- description: JWT Token
in: header
name: Authorization
required: true
type: string
- description: ATS测试仿真-地图数据
in: body
name: RemoveTrainDto
required: true
schema:
$ref: '#/definitions/dto.CheckMapDataReqDto'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/dto.CheckMapDataRspDto'
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: ATS测试仿真地图数据校验
tags:
- ATS测试仿真Api
/api/v1/simulation/create: /api/v1/simulation/create:
post: post:
consumes: consumes:
@ -745,68 +638,6 @@ paths:
summary: 创建ATS测试仿真 summary: 创建ATS测试仿真
tags: tags:
- ATS测试仿真Api - ATS测试仿真Api
/api/v1/simulation/list:
get:
consumes:
- application/json
description: ATS测试仿真-添加列车
parameters:
- description: JWT Token
in: header
name: Authorization
required: true
type: string
produces:
- application/json
responses:
"200":
description: OK
schema:
items:
$ref: '#/definitions/dto.SimulationInfoRepDto'
type: array
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 获取ATS测试系统所有仿真实例的基本信息
tags:
- ATS测试仿真Api
/api/v1/simulation/switch/operation:
post:
consumes:
- application/json
description: ATS测试仿真-添加列车
parameters:
- description: JWT Token
in: header
name: Authorization
required: true
type: string
- description: ATS测试仿真-操作道岔
in: body
name: RemoveTrainDto
required: true
schema:
$ref: '#/definitions/dto.SwitchOperationReqDto'
produces:
- application/json
responses:
"200":
description: OK
schema:
type: string
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: 获取ATS测试-操作道岔
tags:
- ATS测试仿真Api
/api/v1/simulation/train/add: /api/v1/simulation/train/add:
post: post:
consumes: consumes:
@ -840,71 +671,6 @@ paths:
summary: ATS测试仿真-添加列车 summary: ATS测试仿真-添加列车
tags: tags:
- ATS测试仿真Api - ATS测试仿真Api
/api/v1/simulation/train/destroy/{id}:
get:
consumes:
- application/json
description: ATS测试仿真-添加列车
parameters:
- description: JWT Token
in: header
name: Authorization
required: true
type: string
- description: 仿真id
in: path
name: id
required: true
type: integer
produces:
- application/json
responses:
"200":
description: OK
schema:
type: string
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: ATS仿真销毁
tags:
- ATS测试仿真Api
/api/v1/simulation/train/remove:
post:
consumes:
- application/json
description: ATS测试仿真-移除列车
parameters:
- description: JWT Token
in: header
name: Authorization
required: true
type: string
- description: ATS测试仿真-移除列车
in: body
name: RemoveTrainDto
required: true
schema:
$ref: '#/definitions/dto.RemoveTrainDto'
produces:
- application/json
responses:
"200":
description: OK
schema:
type: string
"500":
description: Internal Server Error
schema:
$ref: '#/definitions/dto.ErrorDto'
security:
- JwtAuth: []
summary: ATS测试仿真-移除列车
tags:
- ATS测试仿真Api
/api/v1/user/current: /api/v1/user/current:
get: get:
consumes: consumes:

View File

@ -1,5 +1,11 @@
package dto package dto
import (
"encoding/json"
"fmt"
"time"
)
type TokenRespDto struct { type TokenRespDto struct {
Code int `json:"code"` Code int `json:"code"`
Token string `json:"token"` Token string `json:"token"`
@ -31,6 +37,27 @@ type PageDto struct {
Records any `form:"records" json:"records"` Records any `form:"records" json:"records"`
} }
type JsonTime time.Time
func (jt *JsonTime) MarshalJSON() ([]byte, error) {
format := time.Time(*jt).Format(time.DateTime)
return json.Marshal(format)
}
func (jt *JsonTime) UnmarshalJSON(data []byte) error {
var str string
err := json.Unmarshal(data, &str)
if err != nil {
panic(ErrorDto{ArgumentParseError, fmt.Sprintf("时间参数解析出错:\n%s", err.Error())})
}
parse, err := time.Parse(time.DateTime, str)
if err != nil {
panic(ErrorDto{ArgumentParseError, fmt.Sprintf("时间参数格式化出错:\n%s", err.Error())})
}
*jt = JsonTime(parse)
return nil
}
// 数据库分页偏移 // 数据库分页偏移
func (p *PageQueryDto) Offset() int { func (p *PageQueryDto) Offset() int {
if p.Page > 0 { if p.Page > 0 {

15
dto/error.go Normal file
View File

@ -0,0 +1,15 @@
package dto
type ErrorCode int
// 1xxx表示各种逻辑错误
// 2xxx表示各种数据错误
// 3xxx表示各种参数错误
const (
LogicError = 1000
DataNotExist = 2000
DataAlreadyExist = 2001
// DataOperationError 数据操作错误(增删改查操作出了意料之外的错误都算)
DataOperationError = 2002
ArgumentParseError = 3000
)

View File

@ -1,5 +1,7 @@
package dto package dto
import "time"
type PublishedGiReqDto struct { type PublishedGiReqDto struct {
PageQueryDto PageQueryDto
Name string `json:"name" form:"name"` Name string `json:"name" form:"name"`
@ -10,6 +12,14 @@ type PublishReqDto struct {
Name string `json:"name" form:"name"` Name string `json:"name" form:"name"`
//草稿数据的id //草稿数据的id
DraftId int32 `json:"draftId" form:"draftId"` DraftId int32 `json:"draftId" form:"draftId"`
//是否覆盖同名数据 ////是否覆盖同名数据
Overwrite bool `json:"overwrite" form:"overwrite"` //Overwrite bool `json:"overwrite" form:"overwrite"`
}
type PublishedGi struct {
ID int32
Name string
Proto []byte
UserID int32
PublishAt time.Time
} }

View File

@ -2,7 +2,6 @@ package service
import ( import (
"fmt" "fmt"
"gorm.io/gorm/clause"
"joylink.club/bj-rtsts-server/db/dbquery" "joylink.club/bj-rtsts-server/db/dbquery"
"joylink.club/bj-rtsts-server/db/model" "joylink.club/bj-rtsts-server/db/model"
"joylink.club/bj-rtsts-server/dto" "joylink.club/bj-rtsts-server/dto"
@ -45,19 +44,13 @@ func PublishFormDraft(req *dto.PublishReqDto, user *model.User) {
UserID: user.ID, UserID: user.ID,
PublishAt: time.Now(), PublishAt: time.Now(),
} }
//删除同名数据
query := dbquery.PublishedGi.Debug() dbquery.PublishedGi.Debug().Where(dbquery.PublishedGi.Name.Eq(req.Name)).Delete()
if req.Overwrite { //插入新数据
query.Clauses(clause.OnConflict{ err := dbquery.PublishedGi.Debug().Create(&entity)
Columns: []clause.Column{{Name: "name"}}, if err != nil {
UpdateAll: true, panic(dto.ErrorDto{Code: dto.DataOperationError, Message: fmt.Sprintf("数据创建失败:\n%s", err.Error())})
})
} else {
query.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "name"}},
})
} }
_ = query.Create(&entity)
} }
func DeletePublishedGiById(id int) { func DeletePublishedGiById(id int) {