Ver código fonte

优化Swagger

Simon Zhou 5 anos atrás
pai
commit
c5b86b0435
9 arquivos alterados com 274 adições e 53 exclusões
  1. 22 24
      controllers/cptrade/cpTrade.go
  2. 89 8
      docs/docs.go
  3. 89 8
      docs/swagger.json
  4. 67 7
      docs/swagger.yaml
  5. 1 1
      global/e/code.go
  6. 1 1
      global/e/msg.go
  7. 0 4
      go.mod
  8. 4 0
      main.go
  9. 1 0
      routers/router.go

+ 22 - 24
controllers/cptrade/cpTrade.go

@@ -20,25 +20,23 @@ type QueryPresaleApplyReq struct {
 
 // Cptradepresaleapply CPTRADE_PRESALEAPPLY 产能预售申请表
 type Cptradepresaleapply struct {
-	Applyid         int64     `json:"applyid"  xorm:"'APPLYID'" binding:"required"` // 申请ID(181+Unix秒时间戳(10位)+xxxxxx)
-	Userid          int64     `json:"userid"  xorm:"'USERID'"`                      // 申请人ID
-	Accountid       int64     `json:"accountid"  xorm:"'ACCOUNTID'"`                // 申请人账户ID
-	Goodscode       string    `json:"goodscode"  xorm:"'GOODSCODE'"`                // 商品代码
-	Goodsname       string    `json:"goodsname"  xorm:"'GOODSNAME'"`                // 商品名称
-	Relatedgoodsid  int64     `json:"relatedgoodsid"  xorm:"'RELATEDGOODSID'"`      // 关联交易合约ID
-	Presaleqty      int64     `json:"presaleqty"  xorm:"'PRESALEQTY'"`              // 预售数量
-	Starttime       time.Time `json:"starttime"  xorm:"'STARTTIME'"`                // 预售开始时间
-	Endtime         time.Time `json:"endtime"  xorm:"'ENDTIME'"`                    // 预售结束时间
-	Attachmenturl   string    `json:"attachmenturl"  xorm:"'ATTACHMENTURL'"`        // 附件地址
-	Applystatus     int64     `json:"applystatus"  xorm:"'APPLYSTATUS'"`            // 申请状态 - 1:已提交 2:初审通过 3:初审拒绝 4:初审失败 5复审通过 6:复审拒绝 7:复审失败 8:已撤销
-	Handlestatus    int64     `json:"handlestatus"  xorm:"'HANDLESTATUS'"`          // 处理状态
-	Applytime       time.Time `json:"applytime"  xorm:"'APPLYTIME'"`                // 申请时间
-	Firstremark     string    `json:"firstremark"  xorm:"'FIRSTREMARK'"`            // 初审备注
-	Marketid        int64     `json:"marketid"  xorm:"'MARKETID'"`                  // 预售市场ID
-	Secondauditid   int64     `json:"secondauditid"  xorm:"'SECONDAUDITID'"`        // 复审人
-	Secondaudittime time.Time `json:"secondaudittime"  xorm:"'SECONDAUDITTIME'"`    // 复审时间
-	Secondremark    string    `json:"secondremark"  xorm:"'SECONDREMARK'"`          // 复审备注
-	Tradedate       string    `json:"tradedate"  xorm:"'TRADEDATE'"`                // 交易日(yyyyMMdd)
+	Applyid        int64     `json:"applyid"  xorm:"'APPLYID'" binding:"required"` // 申请ID(181+Unix秒时间戳(10位)+xxxxxx)
+	Userid         int64     `json:"userid"  xorm:"'USERID'"`                      // 申请人ID
+	Accountid      int64     `json:"accountid"  xorm:"'ACCOUNTID'"`                // 申请人账户ID
+	Goodscode      string    `json:"goodscode"  xorm:"'GOODSCODE'"`                // 商品代码
+	Goodsname      string    `json:"goodsname"  xorm:"'GOODSNAME'"`                // 商品名称
+	Relatedgoodsid int64     `json:"relatedgoodsid"  xorm:"'RELATEDGOODSID'"`      // 关联交易合约ID
+	Presaleqty     int64     `json:"presaleqty"  xorm:"'PRESALEQTY'"`              // 预售数量
+	Starttime      time.Time `json:"starttime"  xorm:"'STARTTIME'"`                // 预售开始时间
+	Endtime        time.Time `json:"endtime"  xorm:"'ENDTIME'"`                    // 预售结束时间
+	Attachmenturl  string    `json:"attachmenturl"  xorm:"'ATTACHMENTURL'"`        // 附件地址
+	Applystatus    int64     `json:"applystatus"  xorm:"'APPLYSTATUS'"`            // 申请状态 - 1:已提交 2:初审通过 3:初审拒绝 4:初审失败 5复审通过 6:复审拒绝 7:复审失败 8:已撤销
+	Handlestatus   int64     `json:"handlestatus"  xorm:"'HANDLESTATUS'"`          // 处理状态
+	Applytime      time.Time `json:"applytime"  xorm:"'APPLYTIME'"`                // 申请时间
+	Firstremark    string    `json:"firstremark"  xorm:"'FIRSTREMARK'"`            // 初审备注
+	Marketid       int64     `json:"marketid"  xorm:"'MARKETID'"`                  // 预售市场ID
+	Secondremark   string    `json:"secondremark"  xorm:"'SECONDREMARK'"`          // 复审备注
+	Tradedate      string    `json:"tradedate"  xorm:"'TRADEDATE'"`                // 交易日(yyyyMMdd)
 }
 
 // TableName is
@@ -48,11 +46,11 @@ func (Cptradepresaleapply) TableName() string {
 
 // QueryPreasleApply 查询产能预售申请表信息
 // @Summary 查询产能预售申请表信息
-// @Produce  json
-// @Param userid query int true "账户ID"
-// @Param applyid query int false "申请ID"
-// @Param accountid query int false "资金账户ID"
-// @Success 0 {object} app.Response
+// @Produce json
+// @Param userid path int true "账户ID"
+// @Param applyid path int false "申请ID"
+// @Param accountid path int false "资金账户ID"
+// @Success 200 {object} Cptradepresaleapply
 // @Failure 500 {object} app.Response
 // @Router /CPTrade/QueryPreasleApply [get]
 // @Tags 产能预售

+ 89 - 8
docs/docs.go

@@ -40,29 +40,27 @@ var doc = `{
                         "type": "integer",
                         "description": "账户ID",
                         "name": "userid",
-                        "in": "query",
+                        "in": "path",
                         "required": true
                     },
                     {
                         "type": "integer",
                         "description": "申请ID",
                         "name": "applyid",
-                        "in": "query"
+                        "in": "path"
                     },
                     {
                         "type": "integer",
                         "description": "资金账户ID",
                         "name": "accountid",
-                        "in": "query"
+                        "in": "path"
                     }
                 ],
                 "responses": {
-                    "0": {
+                    "200": {
+                        "description": "OK",
                         "schema": {
-                            "type": "array",
-                            "items": {
-                                "$ref": "#/definitions/app.Response"
-                            }
+                            "$ref": "#/definitions/cptrade.Cptradepresaleapply"
                         }
                     },
                     "500": {
@@ -89,6 +87,89 @@ var doc = `{
                     "type": "string"
                 }
             }
+        },
+        "cptrade.Cptradepresaleapply": {
+            "type": "object",
+            "required": [
+                "applyid"
+            ],
+            "properties": {
+                "accountid": {
+                    "description": "申请人账户ID",
+                    "type": "integer"
+                },
+                "applyid": {
+                    "description": "申请ID(181+Unix秒时间戳(10位)+xxxxxx)",
+                    "type": "integer"
+                },
+                "applystatus": {
+                    "description": "申请状态 - 1:已提交 2:初审通过 3:初审拒绝 4:初审失败 5复审通过 6:复审拒绝 7:复审失败 8:已撤销",
+                    "type": "integer"
+                },
+                "applytime": {
+                    "description": "申请时间",
+                    "type": "string"
+                },
+                "attachmenturl": {
+                    "description": "附件地址",
+                    "type": "string"
+                },
+                "endtime": {
+                    "description": "预售结束时间",
+                    "type": "string"
+                },
+                "firstremark": {
+                    "description": "初审备注",
+                    "type": "string"
+                },
+                "goodscode": {
+                    "description": "商品代码",
+                    "type": "string"
+                },
+                "goodsname": {
+                    "description": "商品名称",
+                    "type": "string"
+                },
+                "handlestatus": {
+                    "description": "处理状态",
+                    "type": "integer"
+                },
+                "marketid": {
+                    "description": "预售市场ID",
+                    "type": "integer"
+                },
+                "presaleqty": {
+                    "description": "预售数量",
+                    "type": "integer"
+                },
+                "relatedgoodsid": {
+                    "description": "关联交易合约ID",
+                    "type": "integer"
+                },
+                "secondremark": {
+                    "description": "复审备注",
+                    "type": "string"
+                },
+                "starttime": {
+                    "description": "预售开始时间",
+                    "type": "string"
+                },
+                "tradedate": {
+                    "description": "交易日(yyyyMMdd)",
+                    "type": "string"
+                },
+                "userid": {
+                    "description": "申请人ID",
+                    "type": "integer"
+                }
+            }
+        }
+    },
+    "securityDefinitions": {
+        "ApiKeyAuth": {
+            "type": "apiKey",
+            "name": "token",
+            "in": "header"
         }
     }
 }`

+ 89 - 8
docs/swagger.json

@@ -24,29 +24,27 @@
                         "type": "integer",
                         "description": "账户ID",
                         "name": "userid",
-                        "in": "query",
+                        "in": "path",
                         "required": true
                     },
                     {
                         "type": "integer",
                         "description": "申请ID",
                         "name": "applyid",
-                        "in": "query"
+                        "in": "path"
                     },
                     {
                         "type": "integer",
                         "description": "资金账户ID",
                         "name": "accountid",
-                        "in": "query"
+                        "in": "path"
                     }
                 ],
                 "responses": {
-                    "0": {
+                    "200": {
+                        "description": "OK",
                         "schema": {
-                            "type": "array",
-                            "items": {
-                                "$ref": "#/definitions/app.Response"
-                            }
+                            "$ref": "#/definitions/cptrade.Cptradepresaleapply"
                         }
                     },
                     "500": {
@@ -73,6 +71,89 @@
                     "type": "string"
                 }
             }
+        },
+        "cptrade.Cptradepresaleapply": {
+            "type": "object",
+            "required": [
+                "applyid"
+            ],
+            "properties": {
+                "accountid": {
+                    "description": "申请人账户ID",
+                    "type": "integer"
+                },
+                "applyid": {
+                    "description": "申请ID(181+Unix秒时间戳(10位)+xxxxxx)",
+                    "type": "integer"
+                },
+                "applystatus": {
+                    "description": "申请状态 - 1:已提交 2:初审通过 3:初审拒绝 4:初审失败 5复审通过 6:复审拒绝 7:复审失败 8:已撤销",
+                    "type": "integer"
+                },
+                "applytime": {
+                    "description": "申请时间",
+                    "type": "string"
+                },
+                "attachmenturl": {
+                    "description": "附件地址",
+                    "type": "string"
+                },
+                "endtime": {
+                    "description": "预售结束时间",
+                    "type": "string"
+                },
+                "firstremark": {
+                    "description": "初审备注",
+                    "type": "string"
+                },
+                "goodscode": {
+                    "description": "商品代码",
+                    "type": "string"
+                },
+                "goodsname": {
+                    "description": "商品名称",
+                    "type": "string"
+                },
+                "handlestatus": {
+                    "description": "处理状态",
+                    "type": "integer"
+                },
+                "marketid": {
+                    "description": "预售市场ID",
+                    "type": "integer"
+                },
+                "presaleqty": {
+                    "description": "预售数量",
+                    "type": "integer"
+                },
+                "relatedgoodsid": {
+                    "description": "关联交易合约ID",
+                    "type": "integer"
+                },
+                "secondremark": {
+                    "description": "复审备注",
+                    "type": "string"
+                },
+                "starttime": {
+                    "description": "预售开始时间",
+                    "type": "string"
+                },
+                "tradedate": {
+                    "description": "交易日(yyyyMMdd)",
+                    "type": "string"
+                },
+                "userid": {
+                    "description": "申请人ID",
+                    "type": "integer"
+                }
+            }
+        }
+    },
+    "securityDefinitions": {
+        "ApiKeyAuth": {
+            "type": "apiKey",
+            "name": "token",
+            "in": "header"
         }
     }
 }

+ 67 - 7
docs/swagger.yaml

@@ -9,6 +9,62 @@ definitions:
       msg:
         type: string
     type: object
+  cptrade.Cptradepresaleapply:
+    properties:
+      accountid:
+        description: 申请人账户ID
+        type: integer
+      applyid:
+        description: 申请ID(181+Unix秒时间戳(10位)+xxxxxx)
+        type: integer
+      applystatus:
+        description: 申请状态 - 1:已提交 2:初审通过 3:初审拒绝 4:初审失败 5复审通过 6:复审拒绝 7:复审失败 8:已撤销
+        type: integer
+      applytime:
+        description: 申请时间
+        type: string
+      attachmenturl:
+        description: 附件地址
+        type: string
+      endtime:
+        description: 预售结束时间
+        type: string
+      firstremark:
+        description: 初审备注
+        type: string
+      goodscode:
+        description: 商品代码
+        type: string
+      goodsname:
+        description: 商品名称
+        type: string
+      handlestatus:
+        description: 处理状态
+        type: integer
+      marketid:
+        description: 预售市场ID
+        type: integer
+      presaleqty:
+        description: 预售数量
+        type: integer
+      relatedgoodsid:
+        description: 关联交易合约ID
+        type: integer
+      secondremark:
+        description: 复审备注
+        type: string
+      starttime:
+        description: 预售开始时间
+        type: string
+      tradedate:
+        description: 交易日(yyyyMMdd)
+        type: string
+      userid:
+        description: 申请人ID
+        type: integer
+    required:
+    - applyid
+    type: object
 info:
   contact: {}
   description: 新的查询服务,替代原通用查询服务。
@@ -21,26 +77,25 @@ paths:
     get:
       parameters:
       - description: 账户ID
-        in: query
+        in: path
         name: userid
         required: true
         type: integer
       - description: 申请ID
-        in: query
+        in: path
         name: applyid
         type: integer
       - description: 资金账户ID
-        in: query
+        in: path
         name: accountid
         type: integer
       produces:
       - application/json
       responses:
-        "0":
+        "200":
+          description: OK
           schema:
-            items:
-              $ref: '#/definitions/app.Response'
-            type: array
+            $ref: '#/definitions/cptrade.Cptradepresaleapply'
         "500":
           description: Internal Server Error
           schema:
@@ -48,4 +103,9 @@ paths:
       summary: 查询产能预售申请表信息
       tags:
       - 产能预售
+securityDefinitions:
+  ApiKeyAuth:
+    in: header
+    name: token
+    type: apiKey
 swagger: "2.0"

+ 1 - 1
global/e/code.go

@@ -1,7 +1,7 @@
 package e
 
 const (
-	SUCCESS        = 0
+	SUCCESS        = 200
 	ERROR          = 500
 	INVALID_PARAMS = 400
 

+ 1 - 1
global/e/msg.go

@@ -1,7 +1,7 @@
 package e
 
 var MsgFlags = map[int]string{
-	SUCCESS:                         "success",
+	SUCCESS:                         "ok",
 	ERROR:                           "fail",
 	INVALID_PARAMS:                  "请求参数错误",
 	ERROR_AUTH_CHECK_TOKEN_MISSING:  "Token缺失",

+ 0 - 4
go.mod

@@ -7,7 +7,6 @@ require (
 	github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53 // indirect
 	github.com/CloudyKit/jet v2.1.2+incompatible // indirect
 	github.com/DeanThompson/ginpprof v0.0.0-20190408063150-3be636683586
-	github.com/EDDYCJY/go-gin-example v0.0.0-20200505102242-63963976dee0
 	github.com/agrison/go-tablib v0.0.0-20160310143025-4930582c22ee // indirect
 	github.com/agrison/mxj v0.0.0-20160310142625-1269f8afb3b4 // indirect
 	github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
@@ -30,7 +29,6 @@ require (
 	github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
 	github.com/sirupsen/logrus v1.4.2
 	github.com/streadway/amqp v0.0.0-20200108173154-1c71cc93ed71
-	github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14
 	github.com/swaggo/gin-swagger v1.2.0
 	github.com/swaggo/swag v1.5.1
 	github.com/syndtr/goleveldb v1.0.0 // indirect
@@ -40,6 +38,4 @@ require (
 	github.com/xormplus/core v0.0.0-20200308074340-f3bce19d5f31
 	github.com/xormplus/xorm v0.0.0-20200529061552-7d0d26c6f81c
 	gopkg.in/flosch/pongo2.v3 v3.0.0-20141028000813-5e81b817a0c4 // indirect
-	gopkg.in/go-playground/assert.v1 v1.2.1 // indirect
-	gopkg.in/go-playground/validator.v9 v9.29.1 // indirect
 )

+ 4 - 0
main.go

@@ -24,6 +24,10 @@ import (
 // @description 新的查询服务,替代原通用查询服务。
 // @termsOfService http://muchinfo.cn
 //
+// @securityDefinitions.apikey ApiKeyAuth
+// @in header
+// @name token
+//
 // @BasePath /api
 func main() {
 	// 初始化配置

+ 1 - 0
routers/router.go

@@ -7,6 +7,7 @@ import (
 
 	"github.com/gin-gonic/gin"
 
+	// Swagger生成的文档
 	_ "mtp2_if/docs"
 
 	ginSwagger "github.com/swaggo/gin-swagger"