Selaa lähdekoodia

1.增加查持仓明细接口
2.fix bug: 合约买卖大厅详情应显示关联的仓单品类要素项,而不是升贴水配置项

zou.yingbin 4 vuotta sitten
vanhempi
commit
ef142ce10c
6 muutettua tiedostoa jossa 926 lisäystä ja 91 poistoa
  1. 34 0
      controllers/tradexx/qryTradexx.go
  2. 240 0
      docs/docs.go
  3. 240 0
      docs/swagger.json
  4. 172 0
      docs/swagger.yaml
  5. 209 85
      models/tradexx.go
  6. 31 6
      models/wrTrade2.go

+ 34 - 0
controllers/tradexx/qryTradexx.go

@@ -0,0 +1,34 @@
+/**
+* @Author: zou.yingbin
+* @Create  : 2021/9/6 16:50
+* @Modify  : 2021/9/6 16:50
+ */
+
+package tradexx
+
+import (
+	"github.com/gin-gonic/gin"
+	"mtp2_if/global/app"
+	"mtp2_if/models"
+)
+
+// QueryTradeHolderDetail
+// @Summary 查询持仓明细
+// @Produce json
+// @Security ApiKeyAuth
+// @Param userid query int false "用户id"
+// @Param accids query string false "资金账号, 格式 1,2,3"
+// @Param trademodes query string false "交易模式, 格式 1,2,3"
+// @Param marketids query string false "市场id, 格式 1,2,3"
+// @Param goodsid query int false "商品id"
+// @Param buyorsell query int false "买卖方向 0-买 1-卖"
+// @Success 200 {array} models.TradeHolderDetail
+// @Failure 500 {object} app.Response
+// @Router /WrTrade2/QueryTradeHolderDetail [get]
+// @Tags 仓单贸易v2
+func QueryTradeHolderDetail(c *gin.Context) {
+	a := app.GinUtils{Gin: app.Gin{C: c}}
+	m := models.TradeHolderDetail{}
+	a.DoBindReq(&m)
+	a.DoGetDataI(&m)
+}

+ 240 - 0
docs/docs.go

@@ -11636,6 +11636,77 @@ var doc = `{
                 }
             }
         },
+        "/WrTrade2/QueryTradeHolderDetail": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "仓单贸易v2"
+                ],
+                "summary": "查询持仓明细",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户id",
+                        "name": "userid",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "资金账号, 格式 1,2,3",
+                        "name": "accids",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "交易模式, 格式 1,2,3",
+                        "name": "trademodes",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "市场id, 格式 1,2,3",
+                        "name": "marketids",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "商品id",
+                        "name": "goodsid",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "买卖方向 0-买 1-卖",
+                        "name": "buyorsell",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/models.TradeHolderDetail"
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/WrTrade2/QueryWrAverageTradePrice": {
             "get": {
                 "security": [
@@ -30155,6 +30226,175 @@ var doc = `{
                 }
             }
         },
+        "models.TradeHolderDetail": {
+            "type": "object",
+            "properties": {
+                "accountid": {
+                    "description": "账号ID",
+                    "type": "integer"
+                },
+                "agreeunit": {
+                    "description": "合约乘数",
+                    "type": "number"
+                },
+                "buyorsell": {
+                    "description": "方向 - 0:买 1:卖",
+                    "type": "integer"
+                },
+                "currencyid": {
+                    "description": "商品币种id",
+                    "type": "integer"
+                },
+                "currencyname": {
+                    "description": "币种名称",
+                    "type": "string"
+                },
+                "decimalplace": {
+                    "description": "商品价格小数位",
+                    "type": "integer"
+                },
+                "enumdicname": {
+                    "description": "商品单位名称",
+                    "type": "string"
+                },
+                "expirecycle": {
+                    "description": "行权周期(天) -  1:滚动行权时填写",
+                    "type": "integer"
+                },
+                "expiredate": {
+                    "description": "行权日(yyyyMMdd) - 到期日",
+                    "type": "string"
+                },
+                "expiretype": {
+                    "description": "行权日类型 - 1:滚动行权 2:固定日行权",
+                    "type": "integer"
+                },
+                "freezeqty": {
+                    "description": "冻结数量",
+                    "type": "number"
+                },
+                "goodscode": {
+                    "description": "商品代码",
+                    "type": "string"
+                },
+                "goodsid": {
+                    "description": "商品ID",
+                    "type": "integer"
+                },
+                "goodsname": {
+                    "description": "商品名称",
+                    "type": "string"
+                },
+                "goodunitid": {
+                    "description": "商品单位id",
+                    "type": "integer"
+                },
+                "holderamount": {
+                    "description": "持仓金额",
+                    "type": "number"
+                },
+                "holdercredit": {
+                    "description": "持仓授信金额",
+                    "type": "number"
+                },
+                "holderdays": {
+                    "description": "剩余冻结天数",
+                    "type": "integer"
+                },
+                "holderprice": {
+                    "description": "持仓价格",
+                    "type": "number"
+                },
+                "holderqty": {
+                    "description": "持仓数量",
+                    "type": "number"
+                },
+                "isconfirmexercise": {
+                    "description": "是否确认行权- 0:否 1:是",
+                    "type": "integer"
+                },
+                "ispreexercise": {
+                    "description": "是否预申报- 0:否 1:是 2:不可行权",
+                    "type": "integer"
+                },
+                "marketid": {
+                    "description": "市场id",
+                    "type": "integer"
+                },
+                "marketname": {
+                    "description": "市场名称",
+                    "type": "string"
+                },
+                "openprice": {
+                    "description": "建仓价格",
+                    "type": "number"
+                },
+                "openqty": {
+                    "description": "建仓数量",
+                    "type": "number"
+                },
+                "optiontype": {
+                    "description": "期权类型 - 1:认购(看涨) 2:认沽(看跌)",
+                    "type": "integer"
+                },
+                "preexerciseprice": {
+                    "description": "预申报价格",
+                    "type": "number"
+                },
+                "premium": {
+                    "description": "权利金",
+                    "type": "number"
+                },
+                "qtydecimalplace": {
+                    "description": "商品成交量小数位",
+                    "type": "integer"
+                },
+                "releaseamount": {
+                    "description": "释放持仓金额",
+                    "type": "number"
+                },
+                "releaseholdercredit": {
+                    "description": "释放持仓授信金额",
+                    "type": "number"
+                },
+                "taname": {
+                    "description": "资金账号名称",
+                    "type": "string"
+                },
+                "tradeamount": {
+                    "description": "成交金额",
+                    "type": "number"
+                },
+                "tradedate": {
+                    "description": "交易日(yyyyMMdd)",
+                    "type": "string"
+                },
+                "tradeid": {
+                    "description": "成交单号(101+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)",
+                    "type": "string"
+                },
+                "trademode": {
+                    "description": "交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价 46:掉期",
+                    "type": "integer"
+                },
+                "tradeproperty": {
+                    "description": "交易属性",
+                    "type": "integer"
+                },
+                "tradetime": {
+                    "description": "交易时间",
+                    "type": "string"
+                },
+                "userid": {
+                    "description": "用户id",
+                    "type": "integer"
+                },
+                "username": {
+                    "description": "用户名称",
+                    "type": "string"
+                }
+            }
+        },
         "models.UserCollectConfig": {
             "type": "object",
             "properties": {

+ 240 - 0
docs/swagger.json

@@ -11620,6 +11620,77 @@
                 }
             }
         },
+        "/WrTrade2/QueryTradeHolderDetail": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "仓单贸易v2"
+                ],
+                "summary": "查询持仓明细",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "用户id",
+                        "name": "userid",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "资金账号, 格式 1,2,3",
+                        "name": "accids",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "交易模式, 格式 1,2,3",
+                        "name": "trademodes",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "市场id, 格式 1,2,3",
+                        "name": "marketids",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "商品id",
+                        "name": "goodsid",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "买卖方向 0-买 1-卖",
+                        "name": "buyorsell",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "type": "array",
+                            "items": {
+                                "$ref": "#/definitions/models.TradeHolderDetail"
+                            }
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/WrTrade2/QueryWrAverageTradePrice": {
             "get": {
                 "security": [
@@ -30139,6 +30210,175 @@
                 }
             }
         },
+        "models.TradeHolderDetail": {
+            "type": "object",
+            "properties": {
+                "accountid": {
+                    "description": "账号ID",
+                    "type": "integer"
+                },
+                "agreeunit": {
+                    "description": "合约乘数",
+                    "type": "number"
+                },
+                "buyorsell": {
+                    "description": "方向 - 0:买 1:卖",
+                    "type": "integer"
+                },
+                "currencyid": {
+                    "description": "商品币种id",
+                    "type": "integer"
+                },
+                "currencyname": {
+                    "description": "币种名称",
+                    "type": "string"
+                },
+                "decimalplace": {
+                    "description": "商品价格小数位",
+                    "type": "integer"
+                },
+                "enumdicname": {
+                    "description": "商品单位名称",
+                    "type": "string"
+                },
+                "expirecycle": {
+                    "description": "行权周期(天) -  1:滚动行权时填写",
+                    "type": "integer"
+                },
+                "expiredate": {
+                    "description": "行权日(yyyyMMdd) - 到期日",
+                    "type": "string"
+                },
+                "expiretype": {
+                    "description": "行权日类型 - 1:滚动行权 2:固定日行权",
+                    "type": "integer"
+                },
+                "freezeqty": {
+                    "description": "冻结数量",
+                    "type": "number"
+                },
+                "goodscode": {
+                    "description": "商品代码",
+                    "type": "string"
+                },
+                "goodsid": {
+                    "description": "商品ID",
+                    "type": "integer"
+                },
+                "goodsname": {
+                    "description": "商品名称",
+                    "type": "string"
+                },
+                "goodunitid": {
+                    "description": "商品单位id",
+                    "type": "integer"
+                },
+                "holderamount": {
+                    "description": "持仓金额",
+                    "type": "number"
+                },
+                "holdercredit": {
+                    "description": "持仓授信金额",
+                    "type": "number"
+                },
+                "holderdays": {
+                    "description": "剩余冻结天数",
+                    "type": "integer"
+                },
+                "holderprice": {
+                    "description": "持仓价格",
+                    "type": "number"
+                },
+                "holderqty": {
+                    "description": "持仓数量",
+                    "type": "number"
+                },
+                "isconfirmexercise": {
+                    "description": "是否确认行权- 0:否 1:是",
+                    "type": "integer"
+                },
+                "ispreexercise": {
+                    "description": "是否预申报- 0:否 1:是 2:不可行权",
+                    "type": "integer"
+                },
+                "marketid": {
+                    "description": "市场id",
+                    "type": "integer"
+                },
+                "marketname": {
+                    "description": "市场名称",
+                    "type": "string"
+                },
+                "openprice": {
+                    "description": "建仓价格",
+                    "type": "number"
+                },
+                "openqty": {
+                    "description": "建仓数量",
+                    "type": "number"
+                },
+                "optiontype": {
+                    "description": "期权类型 - 1:认购(看涨) 2:认沽(看跌)",
+                    "type": "integer"
+                },
+                "preexerciseprice": {
+                    "description": "预申报价格",
+                    "type": "number"
+                },
+                "premium": {
+                    "description": "权利金",
+                    "type": "number"
+                },
+                "qtydecimalplace": {
+                    "description": "商品成交量小数位",
+                    "type": "integer"
+                },
+                "releaseamount": {
+                    "description": "释放持仓金额",
+                    "type": "number"
+                },
+                "releaseholdercredit": {
+                    "description": "释放持仓授信金额",
+                    "type": "number"
+                },
+                "taname": {
+                    "description": "资金账号名称",
+                    "type": "string"
+                },
+                "tradeamount": {
+                    "description": "成交金额",
+                    "type": "number"
+                },
+                "tradedate": {
+                    "description": "交易日(yyyyMMdd)",
+                    "type": "string"
+                },
+                "tradeid": {
+                    "description": "成交单号(101+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)",
+                    "type": "string"
+                },
+                "trademode": {
+                    "description": "交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价 46:掉期",
+                    "type": "integer"
+                },
+                "tradeproperty": {
+                    "description": "交易属性",
+                    "type": "integer"
+                },
+                "tradetime": {
+                    "description": "交易时间",
+                    "type": "string"
+                },
+                "userid": {
+                    "description": "用户id",
+                    "type": "integer"
+                },
+                "username": {
+                    "description": "用户名称",
+                    "type": "string"
+                }
+            }
+        },
         "models.UserCollectConfig": {
             "type": "object",
             "properties": {

+ 172 - 0
docs/swagger.yaml

@@ -12896,6 +12896,133 @@ definitions:
     required:
     - autoid
     type: object
+  models.TradeHolderDetail:
+    properties:
+      accountid:
+        description: 账号ID
+        type: integer
+      agreeunit:
+        description: 合约乘数
+        type: number
+      buyorsell:
+        description: 方向 - 0:买 1:卖
+        type: integer
+      currencyid:
+        description: 商品币种id
+        type: integer
+      currencyname:
+        description: 币种名称
+        type: string
+      decimalplace:
+        description: 商品价格小数位
+        type: integer
+      enumdicname:
+        description: 商品单位名称
+        type: string
+      expirecycle:
+        description: 行权周期(天) -  1:滚动行权时填写
+        type: integer
+      expiredate:
+        description: 行权日(yyyyMMdd) - 到期日
+        type: string
+      expiretype:
+        description: 行权日类型 - 1:滚动行权 2:固定日行权
+        type: integer
+      freezeqty:
+        description: 冻结数量
+        type: number
+      goodscode:
+        description: 商品代码
+        type: string
+      goodsid:
+        description: 商品ID
+        type: integer
+      goodsname:
+        description: 商品名称
+        type: string
+      goodunitid:
+        description: 商品单位id
+        type: integer
+      holderamount:
+        description: 持仓金额
+        type: number
+      holdercredit:
+        description: 持仓授信金额
+        type: number
+      holderdays:
+        description: 剩余冻结天数
+        type: integer
+      holderprice:
+        description: 持仓价格
+        type: number
+      holderqty:
+        description: 持仓数量
+        type: number
+      isconfirmexercise:
+        description: 是否确认行权- 0:否 1:是
+        type: integer
+      ispreexercise:
+        description: 是否预申报- 0:否 1:是 2:不可行权
+        type: integer
+      marketid:
+        description: 市场id
+        type: integer
+      marketname:
+        description: 市场名称
+        type: string
+      openprice:
+        description: 建仓价格
+        type: number
+      openqty:
+        description: 建仓数量
+        type: number
+      optiontype:
+        description: 期权类型 - 1:认购(看涨) 2:认沽(看跌)
+        type: integer
+      preexerciseprice:
+        description: 预申报价格
+        type: number
+      premium:
+        description: 权利金
+        type: number
+      qtydecimalplace:
+        description: 商品成交量小数位
+        type: integer
+      releaseamount:
+        description: 释放持仓金额
+        type: number
+      releaseholdercredit:
+        description: 释放持仓授信金额
+        type: number
+      taname:
+        description: 资金账号名称
+        type: string
+      tradeamount:
+        description: 成交金额
+        type: number
+      tradedate:
+        description: 交易日(yyyyMMdd)
+        type: string
+      tradeid:
+        description: 成交单号(101+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
+        type: string
+      trademode:
+        description: 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式
+          21:竞拍-大宗式 22:受托竞价 46:掉期
+        type: integer
+      tradeproperty:
+        description: 交易属性
+        type: integer
+      tradetime:
+        description: 交易时间
+        type: string
+      userid:
+        description: 用户id
+        type: integer
+      username:
+        description: 用户名称
+        type: string
+    type: object
   models.UserCollectConfig:
     properties:
       accountstatus:
@@ -25030,6 +25157,51 @@ paths:
       summary: 查询履约模板
       tags:
       - 仓单贸易v2
+  /WrTrade2/QueryTradeHolderDetail:
+    get:
+      parameters:
+      - description: 用户id
+        in: query
+        name: userid
+        type: integer
+      - description: 资金账号, 格式 1,2,3
+        in: query
+        name: accids
+        type: string
+      - description: 交易模式, 格式 1,2,3
+        in: query
+        name: trademodes
+        type: string
+      - description: 市场id, 格式 1,2,3
+        in: query
+        name: marketids
+        type: string
+      - 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:
+            items:
+              $ref: '#/definitions/models.TradeHolderDetail'
+            type: array
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 查询持仓明细
+      tags:
+      - 仓单贸易v2
   /WrTrade2/QueryWrAverageTradePrice:
     get:
       parameters:

+ 209 - 85
models/tradexx.go

@@ -7,6 +7,7 @@
 package models
 
 import (
+	"fmt"
 	"mtp2_if/db"
 	"mtp2_if/mtpcache"
 	"mtp2_if/utils"
@@ -25,17 +26,14 @@ type TradeGoodsEx struct {
 	CURRENCYID      int32   `json:"currencyid"  xorm:"'CURRENCYID'"`           // 商品币种id
 	CURRENCYNAME    string  `json:"currencyname"  xorm:"'CURRENCYNAME'"`       // 币种名称
 	ENUMDICNAME     string  `json:"enumdicname"  xorm:"'ENUMDICNAME'"`         // 商品单位名称
-	TRADEMODE       int32   `json:"trademode"  xorm:"'TRADEMODE'"`             // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价
+	TRADEMODE       int32   `json:"trademode"  xorm:"'TRADEMODE'"`             // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价 46:掉期
 }
 
 // TradeAccountEx 交易账户相关字段
 type TradeAccountEx struct {
-	TANAME    string `json:"taname"  xorm:"'TANAME'"`       // 资金账号名称
-	USERID    int64  `json:"userid"  xorm:"'USERID'"`       // 用户id
-	USERNAME  string `json:"username"  xorm:"'USERNAME'"`   // 用户名称
-	LOGINID   string `json:"loginid"  xorm:"'LOGINID'"`     // 登录id
-	LOGINCODE string `json:"logincode"  xorm:"'LOGINCODE'"` // 登录代码
-	LOGINNAME string `json:"loginname"  xorm:"'LOGINNAME'"` // 登录名称
+	TANAME   string `json:"taname"  xorm:"'TANAME'"`               // 资金账号名称
+	USERID   int64  `json:"userid"  xorm:"'USERID'" form:"userid"` // 用户id
+	USERNAME string `json:"username"  xorm:"'USERNAME'"`           // 用户名称
 }
 
 // TradePosition 持仓汇总
@@ -83,84 +81,78 @@ func (r *TradePosition) calc() {
 }
 
 func (r *TradePosition) buildSql() string {
-	var sqlId utils.SQLVal = "with gtmp as" +
-		" (select g.goodsid," +
-		"         g.goodsname," +
-		"         g.goodscode," +
-		"         g.decimalplace," +
-		"         g.qtydecimalplace," +
-		"         g.agreeunit," +
-		"         g.marketid," +
-		"         g.goodunitid," +
-		"         g.currencyid," +
-		"         e.enumdicname," +
-		"         e2.enumdicname currencyname," +
-		"         m.marketname," +
-		"         m.trademode" +
-		"    from goods g" +
-		"    left join enumdicitem e" +
-		"      on g.goodunitid = e.enumitemname" +
-		"     and e.enumdiccode = 'goodsunit'" +
-		"    left join enumdicitem e2" +
-		"      on g.currencyid = e2.enumitemname" +
-		"     and e2.enumdiccode = 'currency'" +
-		"    left join market m" +
-		"      on g.marketid = m.marketid)," +
-		"utmp as" +
-		" (select ta.accountid," +
-		"         ta.accountname taname," +
-		"         u.userid," +
-		"         u.accountname  username," +
-		"         a.loginid," +
-		"         b.logincode," +
-		"         b.accountname  loginname" +
-		"    from taaccount ta" +
-		"    left join logintaaccount a" +
-		"      on ta.accountid = a.accountid" +
-		"    left join loginaccount b" +
-		"      on a.loginid = b.loginid" +
-		"    left join useraccount u" +
-		"      on ta.relateduserid = u.userid)" +
-		"select k.*, t1.*, t2.*" +
-		"  from (select t.accountid," +
-		"               t.goodsid," +
-		"               t.holdertype," +
-		"               t.usedmargin," +
-		"               t.tradeproperty," +
-		"               0                    as buyorsell," +
-		"               t.buypositionqty     as oriqty," +
-		"               t.buyholderamount    as oriamount," +
-		"               t.buycurpositionqty  as qty," +
-		"               t.buycurholderamount as amount," +
-		"               t.buyfrozenqty       as frozenqty," +
-		"               t.buyotherfrozenqty  as otherfrozenqty," +
-		"               t.buyopentotalqty    curopenqty," +
-		"               t.buyclosetotalqty   curcloseqty" +
-		"          from tradeposition t" +
-		"         where t.buycurpositionqty > 0" +
-		"        union all" +
-		"        select t.accountid," +
-		"               t.goodsid," +
-		"               t.holdertype," +
-		"               t.usedmargin," +
-		"               t.tradeproperty," +
-		"               1                     as buyorsell," +
-		"               t.sellpositionqty     as oriqty," +
-		"               t.sellholderamount    as oriamount," +
-		"               t.sellcurpositionqty  as qty," +
-		"               t.sellcurholderamount as amount," +
-		"               t.sellfrozenqty       as frozenqty," +
-		"               t.sellotherfrozenqty  as otherfrozenqty," +
-		"               t.sellopentotalqty    as curopenqty," +
-		"               t.sellclosetotalqty   as curcloseqty" +
-		"          from tradeposition t" +
-		"         where t.sellcurpositionqty > 0) k" +
-		"  left join gtmp t1" +
-		"    on k.goodsid = t1.goodsid" +
-		"  left join utmp t2" +
-		"    on k.accountid = t2.accountid" +
-		"  where 1=1"
-
+	var sqlId utils.SQLVal = `
+with gtmp as
+ (select g.goodsid,
+         g.goodsname,
+         g.goodscode,
+         g.decimalplace,
+         g.qtydecimalplace,
+         g.agreeunit,
+         g.marketid,
+         g.goodunitid,
+         g.currencyid,
+         e.enumdicname,
+         e2.enumdicname currencyname,
+         m.marketname,
+         m.trademode
+    from goods g
+    left join enumdicitem e
+      on g.goodunitid = e.enumitemname
+     and e.enumdiccode = 'goodsunit'
+    left join enumdicitem e2
+      on g.currencyid = e2.enumitemname
+     and e2.enumdiccode = 'currency'
+    left join market m
+      on g.marketid = m.marketid),
+utmp as
+ (select ta.accountid,
+         ta.accountname taname,
+         u.userid,
+         u.accountname  username
+    from taaccount ta
+    left join useraccount u
+      on ta.relateduserid = u.userid)
+select k.*, t1.*, t2.*
+  from (select t.accountid,
+               t.goodsid,
+               t.holdertype,
+               t.usedmargin,
+               t.tradeproperty,
+               0                    as buyorsell,
+               t.buypositionqty     as oriqty,
+               t.buyholderamount    as oriamount,
+               t.buycurpositionqty  as qty,
+               t.buycurholderamount as amount,
+               t.buyfrozenqty       as frozenqty,
+               t.buyotherfrozenqty  as otherfrozenqty,
+               t.buyopentotalqty    curopenqty,
+               t.buyclosetotalqty   curcloseqty
+          from tradeposition t
+         where t.buycurpositionqty > 0
+        union all
+        select t.accountid,
+               t.goodsid,
+               t.holdertype,
+               t.usedmargin,
+               t.tradeproperty,
+               1                     as buyorsell,
+               t.sellpositionqty     as oriqty,
+               t.sellholderamount    as oriamount,
+               t.sellcurpositionqty  as qty,
+               t.sellcurholderamount as amount,
+               t.sellfrozenqty       as frozenqty,
+               t.sellotherfrozenqty  as otherfrozenqty,
+               t.sellopentotalqty    as curopenqty,
+               t.sellclosetotalqty   as curcloseqty
+          from tradeposition t
+         where t.sellcurpositionqty > 0) k
+  left join gtmp t1
+    on k.goodsid = t1.goodsid
+  left join utmp t2
+    on k.accountid = t2.accountid
+ where 1 = 1
+`
 	return sqlId.String()
 }
 
@@ -173,3 +165,135 @@ func (r *TradePosition) GetDataEx() (interface{}, error) {
 	}
 	return sData, err
 }
+
+// TradeHolderDetail 持仓明细
+type TradeHolderDetail struct {
+	TRADEID             string   `json:"tradeid"  xorm:"TRADEID" form:"tradeid"`          // 成交单号(101+Unix秒时间戳(10位)+2位(MarketServiceID)+xxxx)
+	TRADEDATE           string   `json:"tradedate"  xorm:"TRADEDATE" form:"tradedate"`    // 交易日(yyyyMMdd)
+	MARKETID            int32    `json:"marketid"  xorm:"MARKETID" form:"marketid"`       // 市场ID
+	GOODSID             int32    `json:"goodsid"  xorm:"GOODSID" form:"goodsid"`          // 商品ID
+	ACCOUNTID           int64    `json:"accountid"  xorm:"ACCOUNTID" form:"accountid"`    // 账号ID
+	BUYORSELL           int32    `json:"buyorsell"  xorm:"BUYORSELL"`                     // 方向 - 0:买 1:卖
+	OPENQTY             SFLOAT64 `json:"openqty"  xorm:"OPENQTY"`                         // 建仓数量
+	HOLDERQTY           SFLOAT64 `json:"holderqty"  xorm:"HOLDERQTY"`                     // 持仓数量
+	FREEZEQTY           SFLOAT64 `json:"freezeqty"  xorm:"FREEZEQTY"`                     // 冻结数量
+	OPENPRICE           float64  `json:"openprice"  xorm:"OPENPRICE"`                     // 建仓价格
+	HOLDERPRICE         float64  `json:"holderprice"  xorm:"HOLDERPRICE"`                 // 持仓价格
+	TRADEAMOUNT         float64  `json:"tradeamount"  xorm:"TRADEAMOUNT"`                 // 成交金额
+	HOLDERAMOUNT        float64  `json:"holderamount"  xorm:"HOLDERAMOUNT"`               // 持仓金额
+	RELEASEAMOUNT       float64  `json:"releaseamount"  xorm:"RELEASEAMOUNT"`             // 释放持仓金额
+	HOLDERDAYS          int32    `json:"holderdays"  xorm:"HOLDERDAYS"`                   // 剩余冻结天数
+	TRADETIME           string   `json:"tradetime"  xorm:"TRADETIME"`                     // 交易时间
+	TRADEPROPERTY       int32    `json:"tradeproperty"  xorm:"TRADEPROPERTY"`             // 交易属性
+	OPTIONTYPE          int32    `json:"optiontype"  xorm:"OPTIONTYPE"`                   // 期权类型 - 1:认购(看涨) 2:认沽(看跌)
+	PREMIUM             float64  `json:"premium"  xorm:"PREMIUM"`                         // 权利金
+	EXPIRETYPE          int32    `json:"expiretype"  xorm:"EXPIRETYPE"`                   // 行权日类型 - 1:滚动行权 2:固定日行权
+	EXPIRECYCLE         int32    `json:"expirecycle"  xorm:"EXPIRECYCLE"`                 // 行权周期(天) -  1:滚动行权时填写
+	EXPIREDATE          string   `json:"expiredate"  xorm:"EXPIREDATE" form:"expiredate"` // 行权日(yyyyMMdd) - 到期日
+	ISPREEXERCISE       int32    `json:"ispreexercise"  xorm:"ISPREEXERCISE"`             // 是否预申报- 0:否 1:是 2:不可行权
+	PREEXERCISEPRICE    float64  `json:"preexerciseprice"  xorm:"PREEXERCISEPRICE"`       // 预申报价格
+	ISCONFIRMEXERCISE   int32    `json:"isconfirmexercise"  xorm:"ISCONFIRMEXERCISE"`     // 是否确认行权- 0:否 1:是
+	HOLDERCREDIT        float64  `json:"holdercredit"  xorm:"HOLDERCREDIT"`               // 持仓授信金额
+	RELEASEHOLDERCREDIT float64  `json:"releaseholdercredit"  xorm:"RELEASEHOLDERCREDIT"` // 释放持仓授信金额
+	TradeGoodsEx        `xorm:"extends"`
+	TradeAccountEx      `xorm:"extends"`
+
+	FtAccountIDs string `json:"-" form:"accids"`     // 资金账号,逗号隔开
+	FtTradeMode  string `json:"-" form:"trademodes"` // 交易模式筛选, 逗号隔开
+	FtMarketIDs  string `json:"-" form:"marketids"`  // 市场id, 逗号隔开
+}
+
+func (r *TradeHolderDetail) calc() {
+	if r.QTYDECIMALPLACE != 0 {
+		r.OPENQTY.Power10(r.QTYDECIMALPLACE * -1)
+		r.HOLDERQTY.Power10(r.QTYDECIMALPLACE * -1)
+		r.FREEZEQTY.Power10(r.QTYDECIMALPLACE * -1)
+	}
+}
+
+func (r *TradeHolderDetail) buildSql() string {
+	var sqlId utils.SQLVal = `
+with gtmp as
+ (select g.goodsid,
+         g.goodsname,
+         g.goodscode,
+         g.decimalplace,
+         g.qtydecimalplace,
+         g.agreeunit,
+         g.marketid,
+         g.goodunitid,
+         g.currencyid,
+         e.enumdicname,
+         e2.enumdicname currencyname,
+         m.marketname,
+         m.trademode
+    from goods g
+    left join enumdicitem e
+      on g.goodunitid = e.enumitemname
+     and e.enumdiccode = 'goodsunit'
+    left join enumdicitem e2
+      on g.currencyid = e2.enumitemname
+     and e2.enumdiccode = 'currency'
+    left join market m
+      on g.marketid = m.marketid),
+utmp as
+ (select ta.accountid,
+         ta.accountname taname,
+         u.userid,
+         u.accountname  username
+    from taaccount ta
+    left join useraccount u
+      on ta.relateduserid = u.userid)
+SELECT to_char(t.TRADEID) TRADEID,
+       t.TRADEDATE,
+       t.MARKETID,
+       t.GOODSID,
+       t.ACCOUNTID,
+       t.BUYORSELL,
+       t.OPENQTY,
+       t.HOLDERQTY,
+       t.FREEZEQTY,
+       t.OPENPRICE,
+       t.HOLDERPRICE,
+       t.TRADEAMOUNT,
+       t.HOLDERAMOUNT,
+       t.RELEASEAMOUNT,
+       t.HOLDERDAYS,
+       to_char(t.TRADETIME, 'yyyy-mm-dd hh24:mi:ss') TRADETIME,
+       t.TRADEPROPERTY,
+       t.OPTIONTYPE,
+       t.PREMIUM,
+       t.EXPIRETYPE,
+       t.EXPIRECYCLE,
+       t.EXPIREDATE,
+       t.ISPREEXERCISE,
+       t.PREEXERCISEPRICE,
+       t.ISCONFIRMEXERCISE,
+       t.HOLDERCREDIT,
+       t.RELEASEHOLDERCREDIT,
+       gtmp.*,
+       utmp.*
+  FROM TRADE_HOLDERDETAIL t
+  LEFT JOIN gtmp on t.goodsid=gtmp.goodsid
+  LEFT JOIN utmp on t.accountid=utmp.accountid
+ WHERE 1 = 1
+`
+
+	sqlId.AndEx("utmp.userid", r.USERID, r.USERID > 0)
+	sqlId.AndEx("t.goodsid", r.GOODSID, r.GOODSID > 0)
+	sqlId.JoinEx(r.FtTradeMode != "", fmt.Sprintf(" and gtmp.trademode in(%v)", r.FtTradeMode))
+	sqlId.JoinEx(r.FtMarketIDs != "", fmt.Sprintf(" and gtmp.marketid in(%v)", r.FtMarketIDs))
+	sqlId.JoinEx(r.FtAccountIDs != "", fmt.Sprintf(" and t.accountid in(%v)", r.FtAccountIDs))
+
+	return sqlId.String()
+}
+
+// GetDataEx 获取持仓明细
+func (r *TradeHolderDetail) GetDataEx() (interface{}, error) {
+	sData := make([]TradeHolderDetail, 0)
+	err := db.GetEngine().SQL(r.buildSql()).Find(&sData)
+	for i := range sData {
+		sData[i].calc()
+	}
+	return sData, err
+}

+ 31 - 6
models/wrTrade2.go

@@ -1929,6 +1929,8 @@ type WrStandardFactoryItem struct {
 	DGFACTORYITEMID     int64  `json:"dgfactoryitemid"  xorm:"'DGFACTORYITEMID'"`       // 选择项id
 	DGFACTORYITEMVALUE  string `json:"dgfactoryitemvalue"  xorm:"'DGFACTORYITEMVALUE'"` // 要素项值
 	WAREHOUSEID         int64  `json:"warehouseid"  xorm:"'WAREHOUSEID'"`               // 仓库id
+
+	WMCATFLAG int `json:"-"` // 合同相同项(如有多个仓库, 逗号隔开, 仓库1, 仓库2, 仓库3 ) 1-合并
 }
 
 func (r *WrStandardFactoryItem) calc() {
@@ -1955,6 +1957,29 @@ func (r *WrStandardFactoryItem) buildSql() string {
 		"   and di.isvalid = 1"
 	sqlId.And("t.WRSTANDARDID", r.WRSTANDARDID)
 	sqlId.Join(" order by t.dgfactoryitemtypeid, di.orderindex")
+	// 合并同类项名称
+	if r.WMCATFLAG == 1 {
+		sqlId = `
+select t.wrstandardid,
+       dp.dgfactoryitemtypeid,
+       dp.itemtypename,
+       wm_concat(di.dgfactoryitemvalue) dgfactoryitemvalue
+  from wrstandardfactoryitem t
+ inner join wrstandard w
+    on t.wrstandardid = w.wrstandardid
+ inner join dgfactoryitemtype dp
+    on t.dgfactoryitemtypeid = dp.dgfactoryitemtypeid
+   and dp.deliverygoodsid = w.deliverygoodsid
+ inner join dgfactoryitem di
+    on t.dgfactoryitemid = di.dgfactoryitemid
+   and di.deliverygoodsid = w.deliverygoodsid
+ where dp.isvalid = 1
+   and di.isvalid = 1
+   and t.wrstandardid = %v
+ group by t.wrstandardid, dp.dgfactoryitemtypeid, dp.itemtypename
+`
+		sqlId.FormatParam(r.WRSTANDARDID)
+	}
 	return sqlId.String()
 }
 
@@ -2696,16 +2721,16 @@ func (r *WrBsGoodsInfo) GetDataEx() (interface{}, error) {
 				val.LstItem = append(val.LstItem, WrTypeItem{NAME: "品种", VALUE: vR.DELIVERYGOODSNAME})
 				val.LstItem = append(val.LstItem, WrTypeItem{NAME: "商品", VALUE: vR.WRSTANDARDNAME})
 
-				// 履约关系详情(要素项)
-				mRDetail := DeliveryRelationDetail{GOODSID: r.GOODSID, WMCATFLAG: 1}
-				if d2, err := mRDetail.GetDataEx(); err == nil {
-					if sDetail, ok := d2.([]DeliveryRelationDetail); ok {
-						for i := range sDetail {
+				mItem := WrStandardFactoryItem{WRSTANDARDID: int64(vR.WRSTANDARDID), WMCATFLAG: 1}
+				if d2, err := mItem.GetDataEx(); err == nil {
+					if lst, ok := d2.([]WrStandardFactoryItem); ok {
+						for i := range lst {
 							val.LstItem = append(val.LstItem,
-								WrTypeItem{NAME: sDetail[i].ITEMTYPENAME, VALUE: sDetail[i].DGFACTORYITEMVALUE})
+								WrTypeItem{NAME: lst[i].ITEMTYPENAME, VALUE: lst[i].DGFACTORYITEMVALUE})
 						}
 					}
 				}
+
 				// 履约计划模板步骤
 				tmpId := IFValue(r.BUYORSELL == 0, vR.BUYTEMPLATEID, vR.SELLTEMPLATEID).(int64)
 				mStep := WrGoodsPerformanceStep{TEMPLATEID: tmpId}