Forráskód Böngészése

增加接口: 敞口/期货头寸/期货明细

zou.yingbin 4 éve
szülő
commit
2975df8f9f
6 módosított fájl, 319 hozzáadás és 0 törlés
  1. 26 0
      controllers/ermcp/qryExposure.go
  2. 85 0
      docs/docs.go
  3. 85 0
      docs/swagger.json
  4. 57 0
      docs/swagger.yaml
  5. 65 0
      models/ermcpExposure.go
  6. 1 0
      routers/router.go

+ 26 - 0
controllers/ermcp/qryExposure.go

@@ -243,3 +243,29 @@ func QueryExposureHedgePosition(c *gin.Context) {
 		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
 	}
 }
+
+// 期货明细请求
+type ExposureHedgePosDetailReq struct {
+	AreaUserId    int32 `form:"areaUserId" json:"areaUserId"`       // 所属机构ID
+	GoodsId int32 `form:"goodsId" json:"goodsId"` // 套保商品
+}
+
+// 期货明细应答
+type ExposureHedgePosDetailRsp models.ErmcpHedgePositionDetail
+
+// @Summary 查询敞口期货头寸期货明细(菜单:敞口/期货头寸/期货明细)
+// @Produce json
+// @Security ApiKeyAuth
+// @Param areaUserId query int true "所属机构ID"
+// @Param goodsId query int true "商品id"
+// @Success 200 {array} ExposureHedgePosDetailRsp
+// @Failure 500 {object} app.Response
+// @Router /Ermcp/QueryExposureHedgePositionDetail [get]
+// @Tags 企业风险管理(app)
+func QueryExposureHedgePositionDetail(c *gin.Context) {
+	appG := app.GinUtils{Gin: app.Gin{C: c}}
+	var req ExposureHedgePosDetailReq
+	appG.DoBindReq(&req)
+	m := models.ErmcpHedgePositionDetail{AREAUSERID: req.AreaUserId, HEDGEGOODSID: req.GoodsId}
+	appG.DoGetDataEx(&m)
+}

+ 85 - 0
docs/docs.go

@@ -1140,6 +1140,55 @@ var doc = `{
                 }
             }
         },
+        "/Ermcp/QueryExposureHedgePositionDetail": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "企业风险管理(app)"
+                ],
+                "summary": "查询敞口期货头寸期货明细(菜单:敞口/期货头寸/期货明细)",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "所属机构ID",
+                        "name": "areaUserId",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "商品id",
+                        "name": "goodsId",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/ermcp.ExposureHedgePosDetailRsp"
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Ermcp/QueryExposureSpot": {
             "get": {
                 "security": [
@@ -6298,6 +6347,9 @@ var doc = `{
         "ermcp.ExposureDetailRsp": {
             "$ref": "#/definitions/models.ErmcpExposureDetailModel"
         },
+        "ermcp.ExposureHedgePosDetailRsp": {
+            "$ref": "#/definitions/models.ErmcpHedgePositionDetail"
+        },
         "ermcp.ExposureHedgePositionRsp": {
             "$ref": "#/definitions/models.ErmcpHedgePosition"
         },
@@ -8918,6 +8970,39 @@ var doc = `{
                 }
             }
         },
+        "models.ErmcpHedgePositionDetail": {
+            "type": "object",
+            "properties": {
+                "buyorsell": {
+                    "description": "买卖方向 0-买 1-卖",
+                    "type": "integer"
+                },
+                "channelbuildtype": {
+                    "description": "开平方向 1-建仓 2-平仓",
+                    "type": "integer"
+                },
+                "goodscode": {
+                    "description": "商品代码",
+                    "type": "string"
+                },
+                "goodsname": {
+                    "description": "商品名称",
+                    "type": "string"
+                },
+                "hedgegoodsid": {
+                    "description": "商品id",
+                    "type": "integer"
+                },
+                "tradeqty": {
+                    "description": "数量(成交数量)",
+                    "type": "integer"
+                },
+                "tradetime": {
+                    "description": "时间(成交时间)",
+                    "type": "string"
+                }
+            }
+        },
         "models.ErmcpHisExposure": {
             "type": "object",
             "properties": {

+ 85 - 0
docs/swagger.json

@@ -1124,6 +1124,55 @@
                 }
             }
         },
+        "/Ermcp/QueryExposureHedgePositionDetail": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "企业风险管理(app)"
+                ],
+                "summary": "查询敞口期货头寸期货明细(菜单:敞口/期货头寸/期货明细)",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "所属机构ID",
+                        "name": "areaUserId",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "商品id",
+                        "name": "goodsId",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/ermcp.ExposureHedgePosDetailRsp"
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Ermcp/QueryExposureSpot": {
             "get": {
                 "security": [
@@ -6282,6 +6331,9 @@
         "ermcp.ExposureDetailRsp": {
             "$ref": "#/definitions/models.ErmcpExposureDetailModel"
         },
+        "ermcp.ExposureHedgePosDetailRsp": {
+            "$ref": "#/definitions/models.ErmcpHedgePositionDetail"
+        },
         "ermcp.ExposureHedgePositionRsp": {
             "$ref": "#/definitions/models.ErmcpHedgePosition"
         },
@@ -8902,6 +8954,39 @@
                 }
             }
         },
+        "models.ErmcpHedgePositionDetail": {
+            "type": "object",
+            "properties": {
+                "buyorsell": {
+                    "description": "买卖方向 0-买 1-卖",
+                    "type": "integer"
+                },
+                "channelbuildtype": {
+                    "description": "开平方向 1-建仓 2-平仓",
+                    "type": "integer"
+                },
+                "goodscode": {
+                    "description": "商品代码",
+                    "type": "string"
+                },
+                "goodsname": {
+                    "description": "商品名称",
+                    "type": "string"
+                },
+                "hedgegoodsid": {
+                    "description": "商品id",
+                    "type": "integer"
+                },
+                "tradeqty": {
+                    "description": "数量(成交数量)",
+                    "type": "integer"
+                },
+                "tradetime": {
+                    "description": "时间(成交时间)",
+                    "type": "string"
+                }
+            }
+        },
         "models.ErmcpHisExposure": {
             "type": "object",
             "properties": {

+ 57 - 0
docs/swagger.yaml

@@ -843,6 +843,8 @@ definitions:
     type: object
   ermcp.ExposureDetailRsp:
     $ref: '#/definitions/models.ErmcpExposureDetailModel'
+  ermcp.ExposureHedgePosDetailRsp:
+    $ref: '#/definitions/models.ErmcpHedgePositionDetail'
   ermcp.ExposureHedgePositionRsp:
     $ref: '#/definitions/models.ErmcpHedgePosition'
   ermcp.ExposureSpotDetailRsp:
@@ -2779,6 +2781,30 @@ definitions:
         description: 期初卖头寸
         type: integer
     type: object
+  models.ErmcpHedgePositionDetail:
+    properties:
+      buyorsell:
+        description: 买卖方向 0-买 1-卖
+        type: integer
+      channelbuildtype:
+        description: 开平方向 1-建仓 2-平仓
+        type: integer
+      goodscode:
+        description: 商品代码
+        type: string
+      goodsname:
+        description: 商品名称
+        type: string
+      hedgegoodsid:
+        description: 商品id
+        type: integer
+      tradeqty:
+        description: 数量(成交数量)
+        type: integer
+      tradetime:
+        description: 时间(成交时间)
+        type: string
+    type: object
   models.ErmcpHisExposure:
     properties:
       areauserid:
@@ -7911,6 +7937,37 @@ paths:
       summary: 查询敞口期货头寸(菜单:敞口/期货头寸)
       tags:
       - 企业风险管理(app)
+  /Ermcp/QueryExposureHedgePositionDetail:
+    get:
+      parameters:
+      - description: 所属机构ID
+        in: query
+        name: areaUserId
+        required: true
+        type: integer
+      - description: 商品id
+        in: query
+        name: goodsId
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            items:
+              $ref: '#/definitions/ermcp.ExposureHedgePosDetailRsp'
+            type: array
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 查询敞口期货头寸期货明细(菜单:敞口/期货头寸/期货明细)
+      tags:
+      - 企业风险管理(app)
   /Ermcp/QueryExposureSpot:
     get:
       parameters:

+ 65 - 0
models/ermcpExposure.go

@@ -626,3 +626,68 @@ func (r *ErmcpExposurePostion) GetDataEx() (interface{}, error) {
 	}
 	return sData, nil
 }
+
+// 敞口/期货头寸/期货明细
+type ErmcpHedgePositionDetail struct {
+	HEDGEGOODSID     int32  `json:"hedgegoodsid"  xorm:"'HEDGEGOODSID'"`         // 商品id
+	BUYORSELL        int32  `json:"buyorsell"  xorm:"'BUYORSELL'"`               // 买卖方向 0-买 1-卖
+	TRADEQTY         int32  `json:"tradeqty"  xorm:"'TRADEQTY'"`                 // 数量(成交数量)
+	CHANNELBUILDTYPE int32  `json:"channelbuildtype"  xorm:"'CHANNELBUILDTYPE'"` // 开平方向 1-建仓 2-平仓
+	TRADETIME        string `json:"tradetime"  xorm:"'TRADETIME'"`               // 时间(成交时间)
+	GOODSCODE        string `json:"goodscode"  xorm:"'GOODSCODE'"`               // 商品代码
+	GOODSNAME        string `json:"goodsname"  xorm:"'GOODSNAME'"`               // 商品名称
+	AREAUSERID       int32  `json:"-"`                                           // 所属机构id
+}
+
+func (r *ErmcpHedgePositionDetail) Calc() {
+	if r.BUYORSELL == 1 && r.TRADEQTY > 0{
+		r.TRADEQTY = r.TRADEQTY * -1
+	}
+}
+
+func (r *ErmcpHedgePositionDetail) buildSql() string {
+	sqlId := "select t.hedgegoodsid," +
+		"       t.buyorsell," +
+		"       tradeqty," +
+		"       t.channelbuildtype," +
+		"       to_char(t.tradetime, 'yyyy-mm-dd hh24:mi:ss') tradetime," +
+		"       g.goodscode," +
+		"       g.goodsname" +
+		"  from hedge_outtradedetail t" +
+		" inner join taaccount ta" +
+		"    on t.accountid = ta.accountid" +
+		"   and ta.ismain = 1" +
+		"   and ta.relateduserid = %v" +
+		"  left join goods g" +
+		"    on t.hedgegoodsid = g.goodsid" +
+		" where t.hedgegoodsid = %v" +
+		" union all " +
+		"select t.hedgegoodsid," +
+		"       t.buyorsell," +
+		"       tradeqty," +
+		"       t.channelbuildtype," +
+		"       to_char(t.tradetime, 'yyyy-mm-dd hh24:mi:ss') tradetime," +
+		"       g.goodscode," +
+		"       g.goodsname" +
+		"  from his_hedge_outtradedetail t" +
+		" inner join taaccount ta" +
+		"    on t.accountid = ta.accountid" +
+		"   and ta.ismain = 1" +
+		"   and ta.relateduserid = %v" +
+		"  left join goods g" +
+		"    on t.hedgegoodsid = g.goodsid" +
+		" where t.isvalid = 1" +
+		"   and t.hedgegoodsid = %v"
+	sqlId = fmt.Sprintf(sqlId, r.AREAUSERID, r.HEDGEGOODSID, r.AREAUSERID, r.HEDGEGOODSID)
+	return sqlId
+}
+
+// 获取持仓头寸明细(成交记录)
+func (r *ErmcpHedgePositionDetail) GetDataEx() (interface{}, error) {
+	sData := make([]ErmcpHedgePositionDetail, 0)
+	err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
+	for i := range sData {
+		sData[i].Calc()
+	}
+	return sData, err
+}

+ 1 - 0
routers/router.go

@@ -331,6 +331,7 @@ func InitRouter() *gin.Engine {
 		ermcpR.GET("/QueryAvaildGoodsGroup", ermcp.QueryAvaildGoodsGroup)
 		ermcpR.GET("/QueryRealtimeExposurePosition", ermcp.QueryRealtimeExposurePosition)
 		ermcpR.GET("/QueryExposureHedgePosition", ermcp.QueryExposureHedgePosition)
+		ermcpR.GET("/QueryExposureHedgePositionDetail", ermcp.QueryExposureHedgePositionDetail)
 	}
 
 	return r