Просмотр исходного кода

增加接口: 敞口/期货头寸
fix bug: #93078

zou.yingbin 4 лет назад
Родитель
Сommit
4f1c136447
7 измененных файлов с 477 добавлено и 20 удалено
  1. 37 7
      controllers/ermcp/qryExposure.go
  2. 153 3
      docs/docs.go
  3. 153 3
      docs/swagger.json
  4. 109 3
      docs/swagger.yaml
  5. 1 1
      models/ermcp.go
  6. 23 3
      models/ermcpExposure.go
  7. 1 0
      routers/router.go

+ 37 - 7
controllers/ermcp/qryExposure.go

@@ -126,7 +126,7 @@ func QueryExposureSpot(c *gin.Context) {
 
 // 敞口/现货头寸/现货明细请求
 type ExposureSpotDetailReq struct {
-	AreaUserID   int `form:"areaUserId" binding:"required"`   //所属机构ID
+	AreaUserID   int   `form:"areaUserId" binding:"required"`   //所属机构ID
 	WrstandardId int32 `form:"wrstandardId" binding:"required"` // 现货商品ID
 }
 
@@ -143,7 +143,7 @@ type ExposureSpotDetailRsp models.ErmcpAreaSpotDetailModel
 // @Router /Ermcp/QueryExposureSpotDetail [get]
 // @Tags 企业风险管理(app)
 func QueryExposureSpotDetail(c *gin.Context) {
-	appG := app.GinUtils{Gin:app.Gin{C: c}}
+	appG := app.GinUtils{Gin: app.Gin{C: c}}
 	var req ExposureSpotDetailReq
 	appG.DoBindReq(&req)
 	m := models.ErmcpAreaSpotDetailModel{UserId: req.AreaUserID, WrstandardId: req.WrstandardId}
@@ -187,11 +187,10 @@ func QueryHisExposure(c *gin.Context) {
 	}
 }
 
-
 // 实时敞口/期货明细 请求
 type RealtimeExposurePositionReq struct {
 	AreaUserId    int32 `form:"areaUserId" json:"areaUserId"`       // 所属机构ID
-	MiddleGoodsId int32  `form:"middleGoodsId" json:"middlegoodsid"` // 套保商品
+	MiddleGoodsId int32 `form:"middleGoodsId" json:"middlegoodsid"` // 套保商品
 }
 
 // 实时敞口/期货明细 应答
@@ -206,10 +205,41 @@ type RealtimeExposurePositionRsp models.ErmcpExposurePostion
 // @Failure 500 {object} app.Response
 // @Router /Ermcp/QueryRealtimeExposurePosition [get]
 // @Tags 企业风险管理(app)
-func QueryRealtimeExposurePosition(c *gin.Context)  {
-	appG := app.GinUtils{Gin:app.Gin{C: c}}
+func QueryRealtimeExposurePosition(c *gin.Context) {
+	appG := app.GinUtils{Gin: app.Gin{C: c}}
 	var req RealtimeExposurePositionReq
 	appG.DoBindReq(&req)
 	m := models.ErmcpExposurePostion{AREAUSERID: req.AreaUserId, MIDDLEGOODSID: req.MiddleGoodsId}
 	appG.DoGetDataEx(&m)
-}
+}
+
+// 敞口/期货头寸 请求
+type ExposureHedgePositionReq struct {
+	AreaUserId int32 `form:"areaUserId" json:"areaUserId"` // 所属机构ID
+}
+
+// 敞口/期货头寸 应答
+type ExposureHedgePositionRsp models.ErmcpHedgePosition
+
+// @Summary 查询敞口期货头寸(菜单:敞口/期货头寸)
+// @Produce json
+// @Security ApiKeyAuth
+// @Param areaUserId query int true "所属机构ID"
+// @Success 200 {array} ExposureHedgePositionRsp
+// @Failure 500 {object} app.Response
+// @Router /Ermcp/QueryExposureHedgePosition [get]
+// @Tags 企业风险管理(app)
+func QueryExposureHedgePosition(c *gin.Context) {
+	appG := app.Gin{C: c}
+	var req ExposureHedgePositionReq
+	if err := c.ShouldBind(&req); err != nil {
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+	var m = models.ErmcpHedgePosition{RELATEDUSERID: req.AreaUserId}
+	if d, err := m.GetData(); err == nil {
+		appG.Response(http.StatusOK, e.SUCCESS, d)
+	} else {
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+	}
+}

+ 153 - 3
docs/docs.go

@@ -1098,6 +1098,48 @@ var doc = `{
                 }
             }
         },
+        "/Ermcp/QueryExposureHedgePosition": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "企业风险管理(app)"
+                ],
+                "summary": "查询敞口期货头寸(菜单:敞口/期货头寸)",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "所属机构ID",
+                        "name": "areaUserId",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/ermcp.ExposureHedgePositionRsp"
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Ermcp/QueryExposureSpot": {
             "get": {
                 "security": [
@@ -6256,6 +6298,9 @@ var doc = `{
         "ermcp.ExposureDetailRsp": {
             "$ref": "#/definitions/models.ErmcpExposureDetailModel"
         },
+        "ermcp.ExposureHedgePositionRsp": {
+            "$ref": "#/definitions/models.ErmcpHedgePosition"
+        },
         "ermcp.ExposureSpotDetailRsp": {
             "$ref": "#/definitions/models.ErmcpAreaSpotDetailModel"
         },
@@ -8625,11 +8670,11 @@ var doc = `{
                     "type": "integer"
                 },
                 "diffhedgeqty": {
-                    "description": "套保品种变动量",
+                    "description": "套保品种变动量=持仓变动量*期货合约单位*期货品种系数",
                     "type": "number"
                 },
                 "diffqty": {
-                    "description": "持仓变动量",
+                    "description": "持仓变动量=当前持仓-昨日持仓",
                     "type": "integer"
                 },
                 "goodscode": {
@@ -8768,6 +8813,111 @@ var doc = `{
                 }
             }
         },
+        "models.ErmcpHedgePosition": {
+            "type": "object",
+            "properties": {
+                "accountid": {
+                    "description": "资金账号[外部母账户]",
+                    "type": "integer"
+                },
+                "curbuyposition": {
+                    "description": "期末买头寸",
+                    "type": "integer"
+                },
+                "cursellposition": {
+                    "description": "期末卖头寸",
+                    "type": "integer"
+                },
+                "curtdbuyposition": {
+                    "description": "期末今日买头寸",
+                    "type": "integer"
+                },
+                "curtdsellposition": {
+                    "description": "期末今日卖头寸",
+                    "type": "integer"
+                },
+                "curydbuyposition": {
+                    "description": "期末上日买头寸",
+                    "type": "integer"
+                },
+                "curydsellposition": {
+                    "description": "期末上日卖头寸",
+                    "type": "integer"
+                },
+                "decreaseqty": {
+                    "description": "减少数量 = (期末卖头寸 - 期初卖头寸)*-1",
+                    "type": "integer"
+                },
+                "fretdbuyposition": {
+                    "description": "冻结今日买头寸",
+                    "type": "integer"
+                },
+                "fretdsellposition": {
+                    "description": "冻结今日卖头寸",
+                    "type": "integer"
+                },
+                "freydbuyposition": {
+                    "description": "冻结上日买头寸",
+                    "type": "integer"
+                },
+                "freydsellposition": {
+                    "description": "冻结上日卖头寸",
+                    "type": "integer"
+                },
+                "goodscode": {
+                    "description": "商品代码",
+                    "type": "string"
+                },
+                "goodsid": {
+                    "description": "商品id",
+                    "type": "integer"
+                },
+                "goodsname": {
+                    "description": "商品名称",
+                    "type": "string"
+                },
+                "hedgeaccountcode": {
+                    "description": "对冲账号",
+                    "type": "string"
+                },
+                "hedgegoodsid": {
+                    "description": "对冲合约ID",
+                    "type": "integer"
+                },
+                "increaseqty": {
+                    "description": "增加数量 = 期末买头寸 - 期初买头寸",
+                    "type": "integer"
+                },
+                "marketid": {
+                    "description": "市场ID",
+                    "type": "integer"
+                },
+                "relateduserid": {
+                    "description": "关联用户id",
+                    "type": "integer"
+                },
+                "totalcurqty": {
+                    "description": "当前数量(净头寸) = 期末买头寸 - 期末卖头寸",
+                    "type": "integer"
+                },
+                "totalydqty": {
+                    "description": "昨日数量(净头寸) = 期初买头寸 - 期初卖头寸",
+                    "type": "integer"
+                },
+                "tradedate": {
+                    "description": "交易日(yyyyMMdd)",
+                    "type": "string"
+                },
+                "ydbuyposition": {
+                    "description": "期初买头寸",
+                    "type": "integer"
+                },
+                "ydsellposition": {
+                    "description": "期初卖头寸",
+                    "type": "integer"
+                }
+            }
+        },
         "models.ErmcpHisExposure": {
             "type": "object",
             "properties": {
@@ -9214,7 +9364,7 @@ var doc = `{
                     "type": "integer"
                 },
                 "middleGoodsName": {
-                    "description": "************以下需计算或非redis数据************//",
+                    "description": "套保品种名称",
                     "type": "string"
                 },
                 "needHedgeExposoure": {

+ 153 - 3
docs/swagger.json

@@ -1082,6 +1082,48 @@
                 }
             }
         },
+        "/Ermcp/QueryExposureHedgePosition": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "企业风险管理(app)"
+                ],
+                "summary": "查询敞口期货头寸(菜单:敞口/期货头寸)",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "所属机构ID",
+                        "name": "areaUserId",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/ermcp.ExposureHedgePositionRsp"
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Ermcp/QueryExposureSpot": {
             "get": {
                 "security": [
@@ -6240,6 +6282,9 @@
         "ermcp.ExposureDetailRsp": {
             "$ref": "#/definitions/models.ErmcpExposureDetailModel"
         },
+        "ermcp.ExposureHedgePositionRsp": {
+            "$ref": "#/definitions/models.ErmcpHedgePosition"
+        },
         "ermcp.ExposureSpotDetailRsp": {
             "$ref": "#/definitions/models.ErmcpAreaSpotDetailModel"
         },
@@ -8609,11 +8654,11 @@
                     "type": "integer"
                 },
                 "diffhedgeqty": {
-                    "description": "套保品种变动量",
+                    "description": "套保品种变动量=持仓变动量*期货合约单位*期货品种系数",
                     "type": "number"
                 },
                 "diffqty": {
-                    "description": "持仓变动量",
+                    "description": "持仓变动量=当前持仓-昨日持仓",
                     "type": "integer"
                 },
                 "goodscode": {
@@ -8752,6 +8797,111 @@
                 }
             }
         },
+        "models.ErmcpHedgePosition": {
+            "type": "object",
+            "properties": {
+                "accountid": {
+                    "description": "资金账号[外部母账户]",
+                    "type": "integer"
+                },
+                "curbuyposition": {
+                    "description": "期末买头寸",
+                    "type": "integer"
+                },
+                "cursellposition": {
+                    "description": "期末卖头寸",
+                    "type": "integer"
+                },
+                "curtdbuyposition": {
+                    "description": "期末今日买头寸",
+                    "type": "integer"
+                },
+                "curtdsellposition": {
+                    "description": "期末今日卖头寸",
+                    "type": "integer"
+                },
+                "curydbuyposition": {
+                    "description": "期末上日买头寸",
+                    "type": "integer"
+                },
+                "curydsellposition": {
+                    "description": "期末上日卖头寸",
+                    "type": "integer"
+                },
+                "decreaseqty": {
+                    "description": "减少数量 = (期末卖头寸 - 期初卖头寸)*-1",
+                    "type": "integer"
+                },
+                "fretdbuyposition": {
+                    "description": "冻结今日买头寸",
+                    "type": "integer"
+                },
+                "fretdsellposition": {
+                    "description": "冻结今日卖头寸",
+                    "type": "integer"
+                },
+                "freydbuyposition": {
+                    "description": "冻结上日买头寸",
+                    "type": "integer"
+                },
+                "freydsellposition": {
+                    "description": "冻结上日卖头寸",
+                    "type": "integer"
+                },
+                "goodscode": {
+                    "description": "商品代码",
+                    "type": "string"
+                },
+                "goodsid": {
+                    "description": "商品id",
+                    "type": "integer"
+                },
+                "goodsname": {
+                    "description": "商品名称",
+                    "type": "string"
+                },
+                "hedgeaccountcode": {
+                    "description": "对冲账号",
+                    "type": "string"
+                },
+                "hedgegoodsid": {
+                    "description": "对冲合约ID",
+                    "type": "integer"
+                },
+                "increaseqty": {
+                    "description": "增加数量 = 期末买头寸 - 期初买头寸",
+                    "type": "integer"
+                },
+                "marketid": {
+                    "description": "市场ID",
+                    "type": "integer"
+                },
+                "relateduserid": {
+                    "description": "关联用户id",
+                    "type": "integer"
+                },
+                "totalcurqty": {
+                    "description": "当前数量(净头寸) = 期末买头寸 - 期末卖头寸",
+                    "type": "integer"
+                },
+                "totalydqty": {
+                    "description": "昨日数量(净头寸) = 期初买头寸 - 期初卖头寸",
+                    "type": "integer"
+                },
+                "tradedate": {
+                    "description": "交易日(yyyyMMdd)",
+                    "type": "string"
+                },
+                "ydbuyposition": {
+                    "description": "期初买头寸",
+                    "type": "integer"
+                },
+                "ydsellposition": {
+                    "description": "期初卖头寸",
+                    "type": "integer"
+                }
+            }
+        },
         "models.ErmcpHisExposure": {
             "type": "object",
             "properties": {
@@ -9198,7 +9348,7 @@
                     "type": "integer"
                 },
                 "middleGoodsName": {
-                    "description": "************以下需计算或非redis数据************//",
+                    "description": "套保品种名称",
                     "type": "string"
                 },
                 "needHedgeExposoure": {

+ 109 - 3
docs/swagger.yaml

@@ -843,6 +843,8 @@ definitions:
     type: object
   ermcp.ExposureDetailRsp:
     $ref: '#/definitions/models.ErmcpExposureDetailModel'
+  ermcp.ExposureHedgePositionRsp:
+    $ref: '#/definitions/models.ErmcpHedgePosition'
   ermcp.ExposureSpotDetailRsp:
     $ref: '#/definitions/models.ErmcpAreaSpotDetailModel'
   ermcp.ExposureSpotRsp:
@@ -2594,10 +2596,10 @@ definitions:
         description: 当前持仓
         type: integer
       diffhedgeqty:
-        description: 套保品种变动量
+        description: 套保品种变动量=持仓变动量*期货合约单位*期货品种系数
         type: number
       diffqty:
-        description: 持仓变动量
+        description: 持仓变动量=当前持仓-昨日持仓
         type: integer
       goodscode:
         description: 商品代码
@@ -2699,6 +2701,84 @@ definitions:
         description: 现货商品名称
         type: string
     type: object
+  models.ErmcpHedgePosition:
+    properties:
+      accountid:
+        description: 资金账号[外部母账户]
+        type: integer
+      curbuyposition:
+        description: 期末买头寸
+        type: integer
+      cursellposition:
+        description: 期末卖头寸
+        type: integer
+      curtdbuyposition:
+        description: 期末今日买头寸
+        type: integer
+      curtdsellposition:
+        description: 期末今日卖头寸
+        type: integer
+      curydbuyposition:
+        description: 期末上日买头寸
+        type: integer
+      curydsellposition:
+        description: 期末上日卖头寸
+        type: integer
+      decreaseqty:
+        description: 减少数量 = (期末卖头寸 - 期初卖头寸)*-1
+        type: integer
+      fretdbuyposition:
+        description: 冻结今日买头寸
+        type: integer
+      fretdsellposition:
+        description: 冻结今日卖头寸
+        type: integer
+      freydbuyposition:
+        description: 冻结上日买头寸
+        type: integer
+      freydsellposition:
+        description: 冻结上日卖头寸
+        type: integer
+      goodscode:
+        description: 商品代码
+        type: string
+      goodsid:
+        description: 商品id
+        type: integer
+      goodsname:
+        description: 商品名称
+        type: string
+      hedgeaccountcode:
+        description: 对冲账号
+        type: string
+      hedgegoodsid:
+        description: 对冲合约ID
+        type: integer
+      increaseqty:
+        description: 增加数量 = 期末买头寸 - 期初买头寸
+        type: integer
+      marketid:
+        description: 市场ID
+        type: integer
+      relateduserid:
+        description: 关联用户id
+        type: integer
+      totalcurqty:
+        description: 当前数量(净头寸) = 期末买头寸 - 期末卖头寸
+        type: integer
+      totalydqty:
+        description: 昨日数量(净头寸) = 期初买头寸 - 期初卖头寸
+        type: integer
+      tradedate:
+        description: 交易日(yyyyMMdd)
+        type: string
+      ydbuyposition:
+        description: 期初买头寸
+        type: integer
+      ydsellposition:
+        description: 期初卖头寸
+        type: integer
+    type: object
   models.ErmcpHisExposure:
     properties:
       areauserid:
@@ -3029,7 +3109,7 @@ definitions:
         description: 套保品种
         type: integer
       middleGoodsName:
-        description: '************以下需计算或非redis数据************//'
+        description: 套保品种名称
         type: string
       needHedgeExposoure:
         description: 应套保敞口
@@ -7805,6 +7885,32 @@ paths:
       summary: 查询敞口现货明细
       tags:
       - 企业风险管理(app)
+  /Ermcp/QueryExposureHedgePosition:
+    get:
+      parameters:
+      - description: 所属机构ID
+        in: query
+        name: areaUserId
+        required: true
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            items:
+              $ref: '#/definitions/ermcp.ExposureHedgePositionRsp'
+            type: array
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 查询敞口期货头寸(菜单:敞口/期货头寸)
+      tags:
+      - 企业风险管理(app)
   /Ermcp/QueryExposureSpot:
     get:
       parameters:

+ 1 - 1
models/ermcp.go

@@ -104,7 +104,7 @@ func (r *ErmcpSpotContractModel) buildSql(nQueryType int32) string {
 	case 3:
 		status = "2"
 	case 4:
-		status = "3,5,6"
+		status = "3,5"
 	}
 
 	return fmt.Sprintf(str, status, r.USERID)

+ 23 - 3
models/ermcpExposure.go

@@ -38,7 +38,7 @@ type ErmcpRealExposureModel struct {
 	TotalNeedHedgeQty  float64 // 期货应套保量
 	NeedHedgeExposoure float64 // 应套保敞口
 	NeedHedgeRatio     float64 // 应套保敞口比例
-	//************以下需计算或非redis数据************//
+
 	MiddleGoodsName       string  // 套保品种名称
 	MiddleGoodsCode       string  // 套保品种代码
 	MiddleGoodsHedgeRatio float64 // 应套保比例
@@ -501,6 +501,21 @@ type ErmcpHedgePosition struct {
 	CURTDSELLPOSITION int32  `json:"curtdsellposition"  xorm:"'CURTDSELLPOSITION'"` // 期末今日卖头寸
 	FREYDSELLPOSITION int32  `json:"freydsellposition"  xorm:"'FREYDSELLPOSITION'"` // 冻结上日卖头寸
 	FRETDSELLPOSITION int32  `json:"fretdsellposition"  xorm:"'FRETDSELLPOSITION'"` // 冻结今日卖头寸
+	GOODSID           int32  `json:"goodsid"  xorm:"'GOODSID'"`                     // 商品id
+	GOODSCODE         string `json:"goodscode"  xorm:"'GOODSCODE'"`                 // 商品代码
+	GOODSNAME         string `json:"goodsname"  xorm:"'GOODSNAME'"`                 // 商品名称
+
+	TotalYdQty  int32 `json:"totalydqty"`  // 昨日数量(净头寸) = 期初买头寸 - 期初卖头寸
+	TotalCurQty int32 `json:"totalcurqty"` // 当前数量(净头寸) = 期末买头寸 - 期末卖头寸
+	IncreaseQty int32 `json:"increaseqty"` // 增加数量 = 期末买头寸 - 期初买头寸
+	DecreaseQty int32 `json:"decreaseqty"` // 减少数量 = (期末卖头寸 - 期初卖头寸)*-1
+}
+
+func (r *ErmcpHedgePosition) Calc() {
+	r.TotalYdQty = r.YDBUYPOSITION - r.YDSELLPOSITION
+	r.TotalCurQty = r.CURBUYPOSITION - r.CURSELLPOSITION
+	r.IncreaseQty = r.CURBUYPOSITION - r.YDBUYPOSITION
+	r.DecreaseQty = (r.CURSELLPOSITION - r.YDSELLPOSITION) * -1
 }
 
 func (r *ErmcpHedgePosition) buildSql() string {
@@ -521,12 +536,17 @@ func (r *ErmcpHedgePosition) buildSql() string {
 		"       t.CURYDSELLPOSITION," +
 		"       t.CURTDSELLPOSITION," +
 		"       t.FREYDSELLPOSITION," +
-		"       t.FRETDSELLPOSITION" +
+		"       t.FRETDSELLPOSITION," +
+		"       g.goodsid," +
+		"       g.goodscode," +
+		"       g.goodsname" +
 		"  from hedge_outtradeposition t" +
 		" inner join taaccount ta" +
 		"    on t.accountid = ta.accountid" +
 		"   and ta.ismain = 1" +
-		"   and ta.relateduserid = %v"
+		"   and ta.relateduserid = %v" +
+		"  left join goods g" +
+		"    on t.hedgegoodsid = g.goodsid"
 	sqlId = fmt.Sprintf(sqlId, r.RELATEDUSERID)
 	return sqlId
 }

+ 1 - 0
routers/router.go

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