Procházet zdrojové kódy

增加“获取企业风管期货成交单信息”接口

zhou.xiaoning před 4 roky
rodič
revize
ffc64a4c66
6 změnil soubory, kde provedl 670 přidání a 0 odebrání
  1. 68 0
      controllers/ermcp/qryOrder.go
  2. 144 0
      docs/docs.go
  3. 144 0
      docs/swagger.json
  4. 101 0
      docs/swagger.yaml
  5. 211 0
      models/ermcpOrder.go
  6. 2 0
      routers/router.go

+ 68 - 0
controllers/ermcp/qryOrder.go

@@ -546,3 +546,71 @@ func QueryErmcpOrderDetails(c *gin.Context) {
 	logger.GetLogger().Debugln("QueryErmcpOrderDetails successed: %v", rst)
 	appG.Response(http.StatusOK, e.SUCCESS, rst)
 }
+
+// QueryHedgeTradeDetailReq 获取企业风管期货成交单信息请求参数
+type QueryHedgeTradeDetailReq struct {
+	AccountID int `form:"accountID" binding:"required"`
+	GoodsID   int `form:"goodsID"`
+	BuyOrSell int `form:"buyOrSell"`
+}
+
+// QueryErmcpTradeDetails 获取企业风管期货成交单信息
+// @Summary 获取企业风管期货成交单信息
+// @Produce json
+// @Security ApiKeyAuth
+// @Param accountID query int true "资金账户ID"
+// @Param goodsID query int false "商品ID"
+// @Param buyOrSell query int false "买卖方向,0:买 1:卖"
+// @Success 200 {object} models.QueryHedgeTradeDetailRsp
+// @Failure 500 {object} app.Response
+// @Router /Ermcp/QueryErmcpTradeDetails [get]
+// @Tags 企业风险管理(app)
+func QueryErmcpTradeDetails(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	// 获取请求参数
+	var req QueryHedgeTradeDetailReq
+	if err := appG.C.ShouldBindQuery(&req); err != nil {
+		logger.GetLogger().Errorf("QueryErmcpTradeDetails failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	// 获取资金账户信息
+	taAccount, err := models.GetTaAccountByID(req.AccountID)
+	if err != nil {
+		logger.GetLogger().Errorf("QueryErmcpTradeDetails failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		return
+	}
+	if taAccount == nil {
+		logger.GetLogger().Errorf("QueryErmcpTradeDetails failed")
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		return
+	}
+
+	rst := make([]models.QueryHedgeTradeDetailRsp, 0)
+	if taAccount.Ismain == 1 {
+		// 母账户 -> 外部成交单
+		rst, err = models.GetHedgeOutTradeDetails(req.AccountID, req.GoodsID, req.BuyOrSell)
+		if err != nil {
+			// 查询失败
+			logger.GetLogger().Errorf("QueryErmcpTradeDetails failed: %s", err.Error())
+			appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+			return
+		}
+	} else {
+		// 子账户 -> 内部成交单
+		rst, err = models.GetHedgeInnerTradeDetails(req.AccountID, req.GoodsID, req.BuyOrSell)
+		if err != nil {
+			// 查询失败
+			logger.GetLogger().Errorf("QueryErmcpTradeDetails failed: %s", err.Error())
+			appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+			return
+		}
+	}
+
+	// 查询成功返回
+	logger.GetLogger().Debugln("QueryErmcpTradeDetails successed: %v", rst)
+	appG.Response(http.StatusOK, e.SUCCESS, rst)
+}

+ 144 - 0
docs/docs.go

@@ -1696,6 +1696,57 @@ var doc = `{
                 }
             }
         },
+        "/Ermcp/QueryErmcpTradeDetails": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "企业风险管理(app)"
+                ],
+                "summary": "获取企业风管期货成交单信息",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "资金账户ID",
+                        "name": "accountID",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "商品ID",
+                        "name": "goodsID",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "买卖方向,0:买 1:卖",
+                        "name": "buyOrSell",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/models.QueryHedgeTradeDetailRsp"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Ermcp/QueryErmcpTradePosition": {
             "get": {
                 "security": [
@@ -14473,6 +14524,99 @@ var doc = `{
                 }
             }
         },
+        "models.QueryHedgeTradeDetailRsp": {
+            "type": "object",
+            "properties": {
+                "accountid": {
+                    "description": "账号ID",
+                    "type": "integer"
+                },
+                "buyorsell": {
+                    "description": "方向 - 0:买 1:卖",
+                    "type": "integer"
+                },
+                "channelbuildtype": {
+                    "description": "委托单据类型 0:无 1:建仓 2:平仓",
+                    "type": "integer"
+                },
+                "closecharge": {
+                    "description": "平仓手续费(账户)",
+                    "type": "number"
+                },
+                "closecharge2": {
+                    "description": "平仓手续费(商品)",
+                    "type": "number"
+                },
+                "closetype": {
+                    "description": "平仓方式 - 0:无 1:平今 2:平昨",
+                    "type": "integer"
+                },
+                "curexchangerate": {
+                    "description": "当前汇率",
+                    "type": "number"
+                },
+                "exchangefullname": {
+                    "description": "外部交易所全称",
+                    "type": "string"
+                },
+                "goodscode": {
+                    "description": "商品代码(内部)",
+                    "type": "string"
+                },
+                "goodsid": {
+                    "description": "商品ID",
+                    "type": "integer"
+                },
+                "goodsname": {
+                    "description": "商品名称",
+                    "type": "string"
+                },
+                "marketid": {
+                    "description": "市场ID",
+                    "type": "integer"
+                },
+                "opencharge": {
+                    "description": "建仓手续费(账户)",
+                    "type": "number"
+                },
+                "opencharge2": {
+                    "description": "建仓手续费(商品)",
+                    "type": "number"
+                },
+                "orderid": {
+                    "description": "委托单号",
+                    "type": "string"
+                },
+                "tradeamount": {
+                    "description": "成交金额(账户)",
+                    "type": "number"
+                },
+                "tradedate": {
+                    "description": "交易日(yyyyMMdd)",
+                    "type": "string"
+                },
+                "tradeid": {
+                    "description": "成交单号(108+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)",
+                    "type": "string"
+                },
+                "tradeprice": {
+                    "description": "成交价格",
+                    "type": "number"
+                },
+                "tradeqty": {
+                    "description": "成交数量",
+                    "type": "integer"
+                },
+                "tradetime": {
+                    "description": "成交时间",
+                    "type": "string"
+                },
+                "tradetype": {
+                    "description": "成交类别 - 1:正常委托成交 2:风控斩仓成交 3:修正持仓成交 4:管理端斩仓成交",
+                    "type": "integer"
+                }
+            }
+        },
         "models.QuotePrimaryMenu": {
             "type": "object",
             "properties": {

+ 144 - 0
docs/swagger.json

@@ -1680,6 +1680,57 @@
                 }
             }
         },
+        "/Ermcp/QueryErmcpTradeDetails": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "企业风险管理(app)"
+                ],
+                "summary": "获取企业风管期货成交单信息",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "资金账户ID",
+                        "name": "accountID",
+                        "in": "query",
+                        "required": true
+                    },
+                    {
+                        "type": "integer",
+                        "description": "商品ID",
+                        "name": "goodsID",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "买卖方向,0:买 1:卖",
+                        "name": "buyOrSell",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/models.QueryHedgeTradeDetailRsp"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Ermcp/QueryErmcpTradePosition": {
             "get": {
                 "security": [
@@ -14457,6 +14508,99 @@
                 }
             }
         },
+        "models.QueryHedgeTradeDetailRsp": {
+            "type": "object",
+            "properties": {
+                "accountid": {
+                    "description": "账号ID",
+                    "type": "integer"
+                },
+                "buyorsell": {
+                    "description": "方向 - 0:买 1:卖",
+                    "type": "integer"
+                },
+                "channelbuildtype": {
+                    "description": "委托单据类型 0:无 1:建仓 2:平仓",
+                    "type": "integer"
+                },
+                "closecharge": {
+                    "description": "平仓手续费(账户)",
+                    "type": "number"
+                },
+                "closecharge2": {
+                    "description": "平仓手续费(商品)",
+                    "type": "number"
+                },
+                "closetype": {
+                    "description": "平仓方式 - 0:无 1:平今 2:平昨",
+                    "type": "integer"
+                },
+                "curexchangerate": {
+                    "description": "当前汇率",
+                    "type": "number"
+                },
+                "exchangefullname": {
+                    "description": "外部交易所全称",
+                    "type": "string"
+                },
+                "goodscode": {
+                    "description": "商品代码(内部)",
+                    "type": "string"
+                },
+                "goodsid": {
+                    "description": "商品ID",
+                    "type": "integer"
+                },
+                "goodsname": {
+                    "description": "商品名称",
+                    "type": "string"
+                },
+                "marketid": {
+                    "description": "市场ID",
+                    "type": "integer"
+                },
+                "opencharge": {
+                    "description": "建仓手续费(账户)",
+                    "type": "number"
+                },
+                "opencharge2": {
+                    "description": "建仓手续费(商品)",
+                    "type": "number"
+                },
+                "orderid": {
+                    "description": "委托单号",
+                    "type": "string"
+                },
+                "tradeamount": {
+                    "description": "成交金额(账户)",
+                    "type": "number"
+                },
+                "tradedate": {
+                    "description": "交易日(yyyyMMdd)",
+                    "type": "string"
+                },
+                "tradeid": {
+                    "description": "成交单号(108+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)",
+                    "type": "string"
+                },
+                "tradeprice": {
+                    "description": "成交价格",
+                    "type": "number"
+                },
+                "tradeqty": {
+                    "description": "成交数量",
+                    "type": "integer"
+                },
+                "tradetime": {
+                    "description": "成交时间",
+                    "type": "string"
+                },
+                "tradetype": {
+                    "description": "成交类别 - 1:正常委托成交 2:风控斩仓成交 3:修正持仓成交 4:管理端斩仓成交",
+                    "type": "integer"
+                }
+            }
+        },
         "models.QuotePrimaryMenu": {
             "type": "object",
             "properties": {

+ 101 - 0
docs/swagger.yaml

@@ -6241,6 +6241,75 @@ definitions:
         description: 成交数量
         type: integer
     type: object
+  models.QueryHedgeTradeDetailRsp:
+    properties:
+      accountid:
+        description: 账号ID
+        type: integer
+      buyorsell:
+        description: 方向 - 0:买 1:卖
+        type: integer
+      channelbuildtype:
+        description: 委托单据类型 0:无 1:建仓 2:平仓
+        type: integer
+      closecharge:
+        description: 平仓手续费(账户)
+        type: number
+      closecharge2:
+        description: 平仓手续费(商品)
+        type: number
+      closetype:
+        description: 平仓方式 - 0:无 1:平今 2:平昨
+        type: integer
+      curexchangerate:
+        description: 当前汇率
+        type: number
+      exchangefullname:
+        description: 外部交易所全称
+        type: string
+      goodscode:
+        description: 商品代码(内部)
+        type: string
+      goodsid:
+        description: 商品ID
+        type: integer
+      goodsname:
+        description: 商品名称
+        type: string
+      marketid:
+        description: 市场ID
+        type: integer
+      opencharge:
+        description: 建仓手续费(账户)
+        type: number
+      opencharge2:
+        description: 建仓手续费(商品)
+        type: number
+      orderid:
+        description: 委托单号
+        type: string
+      tradeamount:
+        description: 成交金额(账户)
+        type: number
+      tradedate:
+        description: 交易日(yyyyMMdd)
+        type: string
+      tradeid:
+        description: 成交单号(108+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
+        type: string
+      tradeprice:
+        description: 成交价格
+        type: number
+      tradeqty:
+        description: 成交数量
+        type: integer
+      tradetime:
+        description: 成交时间
+        type: string
+      tradetype:
+        description: 成交类别 - 1:正常委托成交 2:风控斩仓成交 3:修正持仓成交 4:管理端斩仓成交
+        type: integer
+    type: object
   models.QuotePrimaryMenu:
     properties:
       Index:
@@ -9853,6 +9922,38 @@ paths:
       summary: 获取企业风管期货委托单信息
       tags:
       - 企业风险管理(app)
+  /Ermcp/QueryErmcpTradeDetails:
+    get:
+      parameters:
+      - description: 资金账户ID
+        in: query
+        name: accountID
+        required: true
+        type: integer
+      - description: 商品ID
+        in: query
+        name: goodsID
+        type: integer
+      - description: 买卖方向,0:买 1:卖
+        in: query
+        name: buyOrSell
+        type: integer
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/models.QueryHedgeTradeDetailRsp'
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 获取企业风管期货成交单信息
+      tags:
+      - 企业风险管理(app)
   /Ermcp/QueryErmcpTradePosition:
     get:
       description: 本接口只使用于通道交易相关头寸查询;子账户持仓头寸占用保证金为0;

+ 211 - 0
models/ermcpOrder.go

@@ -527,3 +527,214 @@ func GetHedgeOutOrderDetails(accountID int) ([]QueryHedgeOrderDetailRsp, error)
 
 	return rsp, nil
 }
+
+// QueryHedgeTradeDetailRsp 获取企业风管成交单返回模型
+type QueryHedgeTradeDetailRsp struct {
+	Tradeid          string    `json:"tradeid"`          // 成交单号(108+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
+	Buyorsell        int32     `json:"buyorsell"`        // 方向 - 0:买 1:卖
+	Orderid          string    `json:"orderid"`          // 委托单号
+	Tradedate        string    `json:"tradedate"`        // 交易日(yyyyMMdd)
+	Accountid        int64     `json:"accountid"`        // 账号ID
+	Goodsid          int32     `json:"goodsid"`          // 商品ID
+	Marketid         int32     `json:"marketid"`         // 市场ID
+	Tradetime        time.Time `json:"tradetime"`        // 成交时间
+	Tradeprice       float64   `json:"tradeprice"`       // 成交价格
+	Tradeqty         int64     `json:"tradeqty"`         // 成交数量
+	Tradeamount      float64   `json:"tradeamount"`      // 成交金额(账户)
+	Opencharge       float64   `json:"opencharge"`       // 建仓手续费(账户)
+	Closecharge      float64   `json:"closecharge"`      // 平仓手续费(账户)
+	Tradetype        int32     `json:"tradetype"`        // 成交类别 - 1:正常委托成交 2:风控斩仓成交 3:修正持仓成交 4:管理端斩仓成交
+	Channelbuildtype int32     `json:"channelbuildtype"` // 委托单据类型 0:无 1:建仓 2:平仓
+	Closetype        int32     `json:"closetype"`        // 平仓方式 - 0:无 1:平今 2:平昨
+	Curexchangerate  float64   `json:"curexchangerate"`  // 当前汇率
+	Opencharge2      float64   `json:"opencharge2"`      // 建仓手续费(商品)
+	Closecharge2     float64   `json:"closecharge2"`     // 平仓手续费(商品)
+
+	Goodscode string `json:"goodscode"` // 商品代码(内部)
+	Goodsname string `json:"goodsname"` // 商品名称
+
+	Exchangefullname string `json:"exchangefullname"` // 外部交易所全称
+}
+
+// GetHedgeInnerTradeDetails 获取通道交易内部成交单信息
+func GetHedgeInnerTradeDetails(accountID, goodsID, buyOrSell int) ([]QueryHedgeTradeDetailRsp, error) {
+	type tradeDetail struct {
+		Tradeid                  string    `json:"tradeid"  xorm:"'TRADEIDSTR'"`                                // 成交单号(108+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
+		Buyorsell                int32     `json:"buyorsell"  xorm:"'BUYORSELL'"`                               // 方向 - 0:买 1:卖
+		Orderid                  string    `json:"orderid"  xorm:"'ORDERIDSTR'"`                                // 委托单号
+		Tradedate                string    `json:"tradedate"  xorm:"'TRADEDATE'"`                               // 交易日(yyyyMMdd)
+		Accountid                int64     `json:"accountid"  xorm:"'ACCOUNTID'"`                               // 账号ID
+		Goodsid                  int32     `json:"goodsid"  xorm:"'GOODSID'"`                                   // 商品ID
+		Marketid                 int32     `json:"marketid"  xorm:"'MARKETID'"`                                 // 市场ID
+		Tradetime                time.Time `json:"tradetime"  xorm:"'TRADETIME'"`                               // 成交时间
+		Tradeprice               float64   `json:"tradeprice"  xorm:"'TRADEPRICE'"`                             // 成交价格
+		Tradeqty                 int64     `json:"tradeqty"  xorm:"'TRADEQTY'"`                                 // 成交数量
+		Tradeamount              float64   `json:"tradeamount"  xorm:"'TRADEAMOUNT'"`                           // 成交金额(账户)
+		Closepl                  float64   `json:"closepl"  xorm:"'CLOSEPL'"`                                   // 平仓盈亏(账户)
+		Opencharge               float64   `json:"opencharge"  xorm:"'OPENCHARGE'"`                             // 建仓手续费(账户)
+		Closecharge              float64   `json:"closecharge"  xorm:"'CLOSECHARGE'"`                           // 平仓手续费(账户)
+		Tradetype                int32     `json:"tradetype"  xorm:"'TRADETYPE'"`                               // 成交类别 - 1:正常委托成交 2:风控斩仓成交 3:修正持仓成交 4:管理端斩仓成交
+		Channelbuildtype         int32     `json:"channelbuildtype"  xorm:"'CHANNELBUILDTYPE'"`                 // 委托单据类型 0:无 1:建仓 2:平仓
+		Closetype                int32     `json:"closetype"  xorm:"'CLOSETYPE'"`                               // 平仓方式 - 0:无 1:平今 2:平昨
+		Hedgeflag                int32     `json:"hedgeflag"  xorm:"'HEDGEFLAG'"`                               // 投机套保标志 - 0:无 1:投机 2:套保 3:套利
+		Openqty                  int64     `json:"openqty"  xorm:"'OPENQTY'"`                                   // 开仓数量(先建后平操作 需要记录)
+		Closeqty                 int64     `json:"closeqty"  xorm:"'CLOSEQTY'"`                                 // 平仓数量(先建后平操作 需要记录)
+		Status                   int32     `json:"status"  xorm:"'STATUS'"`                                     // 处理状态 - 1:待处理 2:已处理 3:处理失败
+		Isreckoned               int32     `json:"isreckoned"  xorm:"'ISRECKONED'"`                             // 是否结算 - 0:未结算 1:已结算
+		Openfeealgorithm         int32     `json:"openfeealgorithm"  xorm:"'OPENFEEALGORITHM'"`                 // 建仓手续费收取方式  1:比率  2:固定
+		Openchargevalue          float64   `json:"openchargevalue"  xorm:"'OPENCHARGEVALUE'"`                   // 建仓手续费设置值
+		Closefeealgorithm        int32     `json:"closefeealgorithm"  xorm:"'CLOSEFEEALGORITHM'"`               // 平仓手续费收取方式 1:比率  2:固定
+		Closechargevalue         float64   `json:"closechargevalue"  xorm:"'CLOSECHARGEVALUE'"`                 // 平仓手续费设置值
+		Accountcurrencyid        int32     `json:"accountcurrencyid"  xorm:"'ACCOUNTCURRENCYID'"`               // 账户币种ID
+		Goodscurrencyid          int32     `json:"goodscurrencyid"  xorm:"'GOODSCURRENCYID'"`                   // 商品币种ID
+		Curexchangerate          float64   `json:"curexchangerate"  xorm:"'CUREXCHANGERATE'"`                   // 当前汇率
+		Opencharge2              float64   `json:"opencharge2"  xorm:"'OPENCHARGE2'"`                           // 建仓手续费(商品)
+		Closecharge2             float64   `json:"closecharge2"  xorm:"'CLOSECHARGE2'"`                         // 平仓手续费(商品)
+		Closepl2                 float64   `json:"closepl2"  xorm:"'CLOSEPL2'"`                                 // 平仓盈亏(商品)
+		Closepl3                 float64   `json:"closepl3"  xorm:"'CLOSEPL3'"`                                 // 平仓盈亏(账户)(逐笔)
+		Closepl4                 float64   `json:"closepl4"  xorm:"'CLOSEPL4'"`                                 // 平仓盈亏(商品)(逐笔)
+		Extenalopenfeealgorithm  int32     `json:"extenalopenfeealgorithm"  xorm:"'EXTENALOPENFEEALGORITHM'"`   // 建仓手续费收取方式(外部配置) 1:比率  2:固定
+		Extenalopenchargevalue   float64   `json:"extenalopenchargevalue"  xorm:"'EXTENALOPENCHARGEVALUE'"`     // 建仓手续费设置值
+		Extenalclosefeealgorithm int32     `json:"extenalclosefeealgorithm"  xorm:"'EXTENALCLOSEFEEALGORITHM'"` // 平仓手续费收取方式 1:比率  2:固定
+		Extenalclosechargevalue  float64   `json:"extenalclosechargevalue"  xorm:"'EXTENALCLOSECHARGEVALUE'"`   // 平仓手续费设置值
+		Extenalopencharge        float64   `json:"extenalopencharge"  xorm:"'EXTENALOPENCHARGE'"`               // 建仓手续费(商品)(外部)
+		Extenalclosecharge       float64   `json:"extenalclosecharge"  xorm:"'EXTENALCLOSECHARGE'"`             // 平仓手续费(商品)(外部)
+		Parentaccountid          int64     `json:"parentaccountid"  xorm:"'PARENTACCOUNTID'"`                   // 所属母账户
+		Relatedouttradeid        int64     `json:"relatedouttradeid"  xorm:"'RELATEDOUTTRADEID'"`               // 关联外部成交单ID
+
+		Orderidstr       string `xorm:"ORDERIDSTR"`
+		Goodscode        string `xorm:"GOODSCODE"`
+		Goodsname        string `xorm:"GOODSNAME"`
+		Exchangefullname string `xorm:"'EXCHANGEFULLNAME'"`
+	}
+
+	tradeDetails := make([]tradeDetail, 0)
+	session := db.GetEngine().Table("HEDGE_INNERTRADEDETAIL T").
+		Select("to_char(T.TRADEID) TRADEIDSTR, to_char(T.ORDERID) ORDERIDSTR, G.GOODSCODE, G.GOODSNAME, T.*, EX.EXCHANGEFULLNAME").
+		Join("LEFT", "GOODS G", "G.GOODSID = T.GOODSID").
+		Join("LEFT", "GOODSGROUP GG", "GG.GOODSGROUPID = G.GOODSGROUPID").
+		Join("LEFT", "EXTERNALEXCHANGE EX", "GG.EXEXCHANGEID = EX.AUTOID").
+		Where("T.ACCOUNTID = ?", accountID)
+	if goodsID != 0 {
+		session = session.And("T.GOODSID = ?", goodsID)
+	}
+	if buyOrSell != 0 {
+		session = session.And("T.BUYORSELL = ?", buyOrSell)
+	}
+	if err := session.Desc("T.TRADEID").
+		Find(&tradeDetails); err != nil {
+		return nil, err
+	}
+
+	rsp := make([]QueryHedgeTradeDetailRsp, 0)
+	for _, v := range tradeDetails {
+		rsp = append(rsp, QueryHedgeTradeDetailRsp{
+			Tradeid:          v.Tradeid,
+			Buyorsell:        v.Buyorsell,
+			Orderid:          v.Orderid,
+			Tradedate:        v.Tradedate,
+			Accountid:        v.Accountid,
+			Goodsid:          v.Goodsid,
+			Marketid:         v.Marketid,
+			Tradetime:        v.Tradetime,
+			Tradeprice:       v.Tradeprice,
+			Tradeqty:         v.Tradeqty,
+			Tradeamount:      v.Tradeamount,
+			Opencharge:       v.Opencharge,
+			Closecharge:      v.Closecharge,
+			Tradetype:        v.Tradetype,
+			Channelbuildtype: v.Channelbuildtype,
+			Closetype:        v.Closetype,
+			Curexchangerate:  v.Curexchangerate,
+			Opencharge2:      v.Opencharge2,
+			Closecharge2:     v.Closecharge2,
+			Goodscode:        v.Goodscode,
+			Goodsname:        v.Goodsname,
+			Exchangefullname: v.Exchangefullname,
+		})
+	}
+
+	return rsp, nil
+}
+
+// GetHedgeOutTradeDetails 获取通道交易外部成交单信息
+func GetHedgeOutTradeDetails(accountID, goodsID, buyOrSell int) ([]QueryHedgeTradeDetailRsp, error) {
+	type tradeDetail struct {
+		Outtradeid             string    `json:"outtradeid"  xorm:"'OUTTRADEIDSTR'" binding:"required"`   // 外部成交单ID(114+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
+		Tradedate              string    `json:"tradedate"  xorm:"'TRADEDATE'"`                           // 交易日(yyyyMMdd)
+		Relatedoutorderid      string    `json:"relatedoutorderid"  xorm:"'RELATEDOUTORDERIDSTR'"`        // 关联外部委托单ID
+		Accountid              int64     `json:"accountid"  xorm:"'ACCOUNTID'"`                           // 资金账号[外部母账户]
+		Hedgeaccountcode       string    `json:"hedgeaccountcode"  xorm:"'HEDGEACCOUNTCODE'"`             // 对冲账号
+		Marketid               int32     `json:"marketid"  xorm:"'MARKETID'"`                             // 市场ID
+		Hedgegoodsid           int64     `json:"hedgegoodsid"  xorm:"'HEDGEGOODSID'"`                     // 对冲合约ID
+		Buyorsell              int32     `json:"buyorsell"  xorm:"'BUYORSELL'"`                           // 买卖方向 - 0:买 1:卖
+		Channelbuildtype       int32     `json:"channelbuildtype"  xorm:"'CHANNELBUILDTYPE'"`             // 开平标志- 0:无 1:建仓 2:平仓
+		Closetype              int32     `json:"closetype"  xorm:"'CLOSETYPE'"`                           // 平仓方式 - 0:无 1:平今 2:平昨
+		Hedgeflag              int32     `json:"hedgeflag"  xorm:"'HEDGEFLAG'"`                           // 投机套保标志 - 0:无 1:投机 2:套保 3:套利
+		Tradeprice             float64   `json:"tradeprice"  xorm:"'TRADEPRICE'"`                         // 成交价格
+		Tradeqty               int64     `json:"tradeqty"  xorm:"'TRADEQTY'"`                             // 成交数量
+		Tradetime              time.Time `json:"tradetime"  xorm:"'TRADETIME'"`                           // 成交时间
+		Relatedmhpinnerorderid int64     `json:"relatedmhpinnerorderid"  xorm:"'RELATEDMHPINNERORDERID'"` // 接口平台委托单ID
+		Mhpinnertradeid        int64     `json:"mhpinnertradeid"  xorm:"'MHPINNERTRADEID'"`               // 接口平台成交单ID
+		Hasinnerorder          int32     `json:"hasinnerorder"  xorm:"'HASINNERORDER'"`                   // 是否有内部单关联 - 0:无 1:有
+		Isvalid                int32     `json:"isvalid"  xorm:"'ISVALID'"`                               // 是否有效 - 0:无效 1:有效
+		Optiontype             int32     `json:"optiontype"  xorm:"'OPTIONTYPE'"`                         // 期权类型 - 1:认购(看涨) 2:认沽(看跌)
+		Premium                float64   `json:"premium"  xorm:"'PREMIUM'"`                               // 权利金
+		Tradetype              int32     `json:"tradetype"  xorm:"'TRADETYPE'"`                           // 成交类别 - 1:正常委托成交3:修正持仓成交
+
+		Orderidstr       string `xorm:"ORDERIDSTR"`
+		Goodscode        string `xorm:"GOODSCODE"`
+		Goodsname        string `xorm:"GOODSNAME"`
+		Exchangefullname string `xorm:"'EXCHANGEFULLNAME'"`
+
+		Tradeamount float64 `xorm:"TRADEAMOUNT"` // 成交金额
+	}
+
+	tradeDetails := make([]tradeDetail, 0)
+	session := db.GetEngine().Table("HEDGE_OUTTRADEDETAIL T").
+		Select("to_char(T.OUTTRADEID) OUTTRADEIDSTR, to_char(T.RELATEDOUTORDERID) RELATEDOUTORDERIDSTR, G.GOODSCODE, G.GOODSNAME, T.*, EX.EXCHANGEFULLNAME, (T.TRADEPRICE * T.TRADEQTY * G.AGREEUNIT) TRADEAMOUNT").
+		Join("LEFT", "GOODS G", "G.GOODSID = T.HEDGEGOODSID").
+		Join("LEFT", "GOODSGROUP GG", "GG.GOODSGROUPID = G.GOODSGROUPID").
+		Join("LEFT", "EXTERNALEXCHANGE EX", "GG.EXEXCHANGEID = EX.AUTOID").
+		Where("T.ACCOUNTID = ?", accountID)
+	if goodsID != 0 {
+		session = session.And("T.HEDGEGOODSID = ?", goodsID)
+	}
+	if buyOrSell != 0 {
+		session = session.And("T.BUYORSELL = ?", buyOrSell)
+	}
+	if err := session.Desc("T.OUTTRADEID").
+		Find(&tradeDetails); err != nil {
+		return nil, err
+	}
+
+	rsp := make([]QueryHedgeTradeDetailRsp, 0)
+	for _, v := range tradeDetails {
+		rsp = append(rsp, QueryHedgeTradeDetailRsp{
+			Tradeid:          v.Outtradeid,
+			Buyorsell:        v.Buyorsell,
+			Orderid:          v.Relatedoutorderid,
+			Tradedate:        v.Tradedate,
+			Accountid:        v.Accountid,
+			Goodsid:          int32(v.Hedgegoodsid),
+			Marketid:         v.Marketid,
+			Tradetime:        v.Tradetime,
+			Tradeprice:       v.Tradeprice,
+			Tradeqty:         v.Tradeqty,
+			Tradeamount:      v.Tradeamount,
+			Opencharge:       0,
+			Closecharge:      0,
+			Tradetype:        v.Tradetype,
+			Channelbuildtype: v.Channelbuildtype,
+			Closetype:        v.Closetype,
+			Curexchangerate:  1,
+			Opencharge2:      0,
+			Closecharge2:     0,
+			Goodscode:        v.Goodscode,
+			Goodsname:        v.Goodsname,
+			Exchangefullname: v.Exchangefullname,
+		})
+	}
+
+	return rsp, nil
+}

+ 2 - 0
routers/router.go

@@ -365,6 +365,8 @@ func InitRouter() *gin.Engine {
 		ermcpR.GET("/QueryErmcpTradePosition", ermcp.QueryErmcpTradePosition)
 		// 获取企业风管期货委托单信息
 		ermcpR.GET("/QueryErmcpOrderDetails", ermcp.QueryErmcpOrderDetails)
+		// 获取企业风管期货成交单信息
+		ermcpR.GET("/QueryErmcpTradeDetails", ermcp.QueryErmcpTradeDetails)
 	}
 
 	return r