瀏覽代碼

增加查询远期订单信息接口

Simon Zhou 5 年之前
父節點
當前提交
7bcb4c449a
共有 6 個文件被更改,包括 430 次插入5 次删除
  1. 88 0
      controllers/cptrade/cpTrade.go
  2. 16 5
      controllers/wrtrade/wrTrade.go
  3. 120 0
      docs/docs.go
  4. 120 0
      docs/swagger.json
  5. 84 0
      docs/swagger.yaml
  6. 2 0
      routers/router.go

+ 88 - 0
controllers/cptrade/cpTrade.go

@@ -89,3 +89,91 @@ func QueryPreasleApply(c *gin.Context) {
 
 	appG.Response(http.StatusOK, e.SUCCESS, cptradepresaleapplys)
 }
+
+// QueryCPTradeUserGoodsDataReq 远期订单查询请求参数
+type QueryCPTradeUserGoodsDataReq struct {
+	AccountID int `form:"accountid" binding:"required"`
+}
+
+// Cptradeusergoodsdata 用户合约数据表 - 导历史 (远期订单数据)
+type Cptradeusergoodsdata struct {
+	Accountid      int64   `json:"accountid"  xorm:"'ACCOUNTID'" binding:"required"` // 账户ID
+	Goodsid        int64   `json:"goodsid"  xorm:"'GOODSID'" binding:"required"`     // 商品ID
+	Wrstandardid   int64   `json:"wrstandardid"  xorm:"'WRSTANDARDID'"`              // 仓单标准ID
+	Userid         int64   `json:"userid"  xorm:"'USERID'"`                          // 用户ID
+	Inqty          int64   `json:"inqty"  xorm:"'INQTY'"`                            // 转入量
+	Cancelqty      int64   `json:"cancelqty"  xorm:"'CANCELQTY'"`                    // 注销量
+	Deliveryqty    int64   `json:"deliveryqty"  xorm:"'DELIVERYQTY'"`                // 交割量
+	Curpresaleqty  int64   `json:"curpresaleqty"  xorm:"'CURPRESALEQTY'"`            // 当前预售量
+	Presaledqty    int64   `json:"presaledqty"  xorm:"'PRESALEDQTY'"`                // 已预售量
+	Presaledamount int64   `json:"presaledamount"  xorm:"'PRESALEDAMOUNT'"`          // 已预售总金额
+	Marketid       int64   `json:"marketid"  xorm:"'MARKETID'"`                      // 市场ID
+	Freezeamount   float64 `json:"freezeamount"  xorm:"'FREEZEAMOUNT'"`              // 冻结金额
+	Hasspotfreeze  int64   `json:"hasspotfreeze"  xorm:"'HASSPOTFREEZE'"`            // 是否有现货冻结 - 0:否 1:有
+	Goodscode      string  `json:"GoodsCode"`                                        // 订单商品代码
+	Goodsname      string  `json:"GoodsName"`                                        // 订单商品名称
+	Wrstandardcode string  `json:"WRStandardCode"`                                   // 仓单标准代码
+	Wrstandardname string  `json:"WRStandardName"`                                   // 仓单标准名称
+	Enabledqty     int64   `json:"EnabledQty"`                                       // 可用量
+}
+
+// TableName is CPTRADE_USERGOODSDATA
+func (Cptradeusergoodsdata) TableName() string {
+	return "CPTRADE_USERGOODSDATA"
+}
+
+// QueryCPTradeUserGoodsData 查询远期订单信息
+// @Summary 查询远期订单信息
+// @Produce json
+// @Security ApiKeyAuth
+// @Param accountid query int true "资金账户ID"
+// @Success 200 {object} Cptradeusergoodsdata
+// @Failure 500 {object} app.Response
+// @Router /CPTrade/QueryCPTradeUserGoodsData [get]
+// @Tags 产能预售
+func QueryCPTradeUserGoodsData(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	// 获取请求参数
+	var queryCPTradeUserGoodsDataReq QueryCPTradeUserGoodsDataReq
+	if err := appG.C.ShouldBindQuery(&queryCPTradeUserGoodsDataReq); err != nil {
+		logger.GetLogger().Errorf("QueryCPTradeUserGoodsData failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	// 查询数据
+	engine := db.GetEngine()
+	cptradeusergoodsdatas := make([]Cptradeusergoodsdata, 0)
+	err := engine.SQL(`select 
+						t.AccountID,
+						t.GoodsID,
+						t.WRStandardID,
+						t.UserID,
+						t.InQty,
+						t.CancelQty,
+						t.DeliveryQty,
+						t.CurPresaleQty,
+						t.PresaledQty,
+						t.PresaledAmount,
+						t.FreezeAmount,
+						t.MarketID,
+						t.HasSpotFreeze,
+						g.GoodsCode,
+						g.GoodsName,
+						ws.WRStandardCode,
+						ws.WRStandardName,
+						(t.InQty - t.CancelQty - t.DeliveryQty - t.CurPresaleQty) EnabledQty
+						from CPTrade_UserGoodsData t
+						left join goods g on t.goodsid = g.goodsid
+						left join WRStandard ws on t.wrstandardid = ws.wrstandardid
+						where t.accountid = ?`, queryCPTradeUserGoodsDataReq.AccountID).Find(&cptradeusergoodsdatas)
+	if err != nil {
+		// 查询失败
+		logger.GetLogger().Errorf("QueryCPTradeUserGoodsData failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		return
+	}
+
+	appG.Response(http.StatusOK, e.SUCCESS, cptradeusergoodsdatas)
+}

+ 16 - 5
controllers/wrtrade/wrTrade.go

@@ -34,11 +34,12 @@ func (Deliverygoods) TableName() string {
 
 // Wrcategory 仓单分类表
 type Wrcategory struct {
-	Categoryid       int64  `json:"categoryid"  xorm:"'CATEGORYID'" binding:"required"` // 类别ID(SEQ_WRCATEGORY)
-	Categoryname     string `json:"categoryname"  xorm:"'CATEGORYNAME'"`                // 类别名称
-	Parentcategoryid int64  `json:"parentcategoryid"  xorm:"'PARENTCATEGORYID'"`        // 父类别ID
-	Categorydesc     string `json:"categorydesc"  xorm:"'CATEGORYDESC'"`                // 类别描述
-	Iconurl          string `json:"iconurl"  xorm:"'ICONURL'"`                          // 图标地址
+	Categoryid       int64           `json:"categoryid"  xorm:"'CATEGORYID'" binding:"required"` // 类别ID(SEQ_WRCATEGORY)
+	Categoryname     string          `json:"categoryname"  xorm:"'CATEGORYNAME'"`                // 类别名称
+	Parentcategoryid int64           `json:"parentcategoryid"  xorm:"'PARENTCATEGORYID'"`        // 父类别ID
+	Categorydesc     string          `json:"categorydesc"  xorm:"'CATEGORYDESC'"`                // 类别描述
+	Iconurl          string          `json:"iconurl"  xorm:"'ICONURL'"`                          // 图标地址
+	Deliverygoods    []Deliverygoods // 所包含现货种类信息
 }
 
 // TableName is WRCATEGORY
@@ -80,6 +81,16 @@ func GetAllDeliveryGoods(c *gin.Context) {
 	}
 
 	// SELECT w.categoryid,w.categoryname,w.parentcategoryid,w.categorydesc,w.iconurl FROM WRCategory w START WITH Categoryid in (2,2,4) CONNECT BY PRIOR ParentCategoryID = Categoryid;
+	// 查询当前所有品种信息
+	var wrcategorys []Wrcategory
+	if err := engine.SQL("SELECT w.categoryid,w.categoryname,w.parentcategoryid,w.categorydesc,w.iconurl FROM WRCategory w START WITH Categoryid in (?) CONNECT BY PRIOR ParentCategoryID = Categoryid", ids).Find(&wrcategorys); err != nil {
+		// 查询失败
+		logger.GetLogger().Errorf("GetAllDeliveryGoods failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		return
+	}
+
+	// 构建分类与品种的从属关系
 
 	appG.Response(http.StatusOK, e.SUCCESS, deliveryGoodses)
 }

+ 120 - 0
docs/docs.go

@@ -26,6 +26,45 @@ var doc = `{
     "host": "{{.Host}}",
     "basePath": "{{.BasePath}}",
     "paths": {
+        "/CPTrade/QueryCPTradeUserGoodsData": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "产能预售"
+                ],
+                "summary": "查询远期订单信息",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "资金账户ID",
+                        "name": "accountid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/cptrade.Cptradeusergoodsdata"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/CPTrade/QueryPreasleApply": {
             "get": {
                 "security": [
@@ -198,6 +237,87 @@ var doc = `{
                     "type": "integer"
                 }
             }
+        },
+        "cptrade.Cptradeusergoodsdata": {
+            "type": "object",
+            "required": [
+                "accountid",
+                "goodsid"
+            ],
+            "properties": {
+                "EnabledQty": {
+                    "description": "可用量",
+                    "type": "integer"
+                },
+                "GoodsCode": {
+                    "description": "订单商品代码",
+                    "type": "string"
+                },
+                "GoodsName": {
+                    "description": "订单商品名称",
+                    "type": "string"
+                },
+                "WRStandardCode": {
+                    "description": "仓单标准代码",
+                    "type": "string"
+                },
+                "WRStandardName": {
+                    "description": "仓单标准名称",
+                    "type": "string"
+                },
+                "accountid": {
+                    "description": "账户ID",
+                    "type": "integer"
+                },
+                "cancelqty": {
+                    "description": "注销量",
+                    "type": "integer"
+                },
+                "curpresaleqty": {
+                    "description": "当前预售量",
+                    "type": "integer"
+                },
+                "deliveryqty": {
+                    "description": "交割量",
+                    "type": "integer"
+                },
+                "freezeamount": {
+                    "description": "冻结金额",
+                    "type": "number"
+                },
+                "goodsid": {
+                    "description": "商品ID",
+                    "type": "integer"
+                },
+                "hasspotfreeze": {
+                    "description": "是否有现货冻结 - 0:否 1:有",
+                    "type": "integer"
+                },
+                "inqty": {
+                    "description": "转入量",
+                    "type": "integer"
+                },
+                "marketid": {
+                    "description": "市场ID",
+                    "type": "integer"
+                },
+                "presaledamount": {
+                    "description": "已预售总金额",
+                    "type": "integer"
+                },
+                "presaledqty": {
+                    "description": "已预售量",
+                    "type": "integer"
+                },
+                "userid": {
+                    "description": "用户ID",
+                    "type": "integer"
+                },
+                "wrstandardid": {
+                    "description": "仓单标准ID",
+                    "type": "integer"
+                }
+            }
         }
     },
     "securityDefinitions": {

+ 120 - 0
docs/swagger.json

@@ -10,6 +10,45 @@
     },
     "basePath": "/api",
     "paths": {
+        "/CPTrade/QueryCPTradeUserGoodsData": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "产能预售"
+                ],
+                "summary": "查询远期订单信息",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "资金账户ID",
+                        "name": "accountid",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/cptrade.Cptradeusergoodsdata"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/CPTrade/QueryPreasleApply": {
             "get": {
                 "security": [
@@ -182,6 +221,87 @@
                     "type": "integer"
                 }
             }
+        },
+        "cptrade.Cptradeusergoodsdata": {
+            "type": "object",
+            "required": [
+                "accountid",
+                "goodsid"
+            ],
+            "properties": {
+                "EnabledQty": {
+                    "description": "可用量",
+                    "type": "integer"
+                },
+                "GoodsCode": {
+                    "description": "订单商品代码",
+                    "type": "string"
+                },
+                "GoodsName": {
+                    "description": "订单商品名称",
+                    "type": "string"
+                },
+                "WRStandardCode": {
+                    "description": "仓单标准代码",
+                    "type": "string"
+                },
+                "WRStandardName": {
+                    "description": "仓单标准名称",
+                    "type": "string"
+                },
+                "accountid": {
+                    "description": "账户ID",
+                    "type": "integer"
+                },
+                "cancelqty": {
+                    "description": "注销量",
+                    "type": "integer"
+                },
+                "curpresaleqty": {
+                    "description": "当前预售量",
+                    "type": "integer"
+                },
+                "deliveryqty": {
+                    "description": "交割量",
+                    "type": "integer"
+                },
+                "freezeamount": {
+                    "description": "冻结金额",
+                    "type": "number"
+                },
+                "goodsid": {
+                    "description": "商品ID",
+                    "type": "integer"
+                },
+                "hasspotfreeze": {
+                    "description": "是否有现货冻结 - 0:否 1:有",
+                    "type": "integer"
+                },
+                "inqty": {
+                    "description": "转入量",
+                    "type": "integer"
+                },
+                "marketid": {
+                    "description": "市场ID",
+                    "type": "integer"
+                },
+                "presaledamount": {
+                    "description": "已预售总金额",
+                    "type": "integer"
+                },
+                "presaledqty": {
+                    "description": "已预售量",
+                    "type": "integer"
+                },
+                "userid": {
+                    "description": "用户ID",
+                    "type": "integer"
+                },
+                "wrstandardid": {
+                    "description": "仓单标准ID",
+                    "type": "integer"
+                }
+            }
         }
     },
     "securityDefinitions": {

+ 84 - 0
docs/swagger.yaml

@@ -65,6 +65,66 @@ definitions:
     required:
     - applyid
     type: object
+  cptrade.Cptradeusergoodsdata:
+    properties:
+      EnabledQty:
+        description: 可用量
+        type: integer
+      GoodsCode:
+        description: 订单商品代码
+        type: string
+      GoodsName:
+        description: 订单商品名称
+        type: string
+      WRStandardCode:
+        description: 仓单标准代码
+        type: string
+      WRStandardName:
+        description: 仓单标准名称
+        type: string
+      accountid:
+        description: 账户ID
+        type: integer
+      cancelqty:
+        description: 注销量
+        type: integer
+      curpresaleqty:
+        description: 当前预售量
+        type: integer
+      deliveryqty:
+        description: 交割量
+        type: integer
+      freezeamount:
+        description: 冻结金额
+        type: number
+      goodsid:
+        description: 商品ID
+        type: integer
+      hasspotfreeze:
+        description: 是否有现货冻结 - 0:否 1:有
+        type: integer
+      inqty:
+        description: 转入量
+        type: integer
+      marketid:
+        description: 市场ID
+        type: integer
+      presaledamount:
+        description: 已预售总金额
+        type: integer
+      presaledqty:
+        description: 已预售量
+        type: integer
+      userid:
+        description: 用户ID
+        type: integer
+      wrstandardid:
+        description: 仓单标准ID
+        type: integer
+    required:
+    - accountid
+    - goodsid
+    type: object
 info:
   contact: {}
   description: 新的查询服务,替代原通用查询服务。
@@ -73,6 +133,30 @@ info:
   title: MTP2.0 查询服务 API
   version: "1.0"
 paths:
+  /CPTrade/QueryCPTradeUserGoodsData:
+    get:
+      parameters:
+      - description: 资金账户ID
+        in: query
+        name: accountid
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/cptrade.Cptradeusergoodsdata'
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 查询远期订单信息
+      tags:
+      - 产能预售
   /CPTrade/QueryPreasleApply:
     get:
       parameters:

+ 2 - 0
routers/router.go

@@ -41,6 +41,8 @@ func InitRouter() *gin.Engine {
 	{
 		// 查询产能预售申请表
 		cpTradeR.GET("/QueryPreasleApply", cptrade.QueryPreasleApply)
+		// 查询远期订单信息
+		cpTradeR.GET("/QueryCPTradeUserGoodsData", cptrade.QueryCPTradeUserGoodsData)
 	}
 
 	return r