浏览代码

1.查持仓汇总增加标的商品id和代码
2.代码优化

zou.yingbin 4 年之前
父节点
当前提交
1395bfd7ef
共有 8 个文件被更改,包括 285 次插入18 次删除
  1. 11 1
      controllers/order/order.go
  2. 14 2
      controllers/other/logfilelist.go
  3. 23 0
      controllers/tradexx/qryTradexx.go
  4. 79 0
      docs/docs.go
  5. 79 0
      docs/swagger.json
  6. 51 0
      docs/swagger.yaml
  7. 27 15
      models/tradexx.go
  8. 1 0
      routers/router.go

+ 11 - 1
controllers/order/order.go

@@ -80,6 +80,8 @@ type QueryTradePositionRsp struct {
 	MarketAmount    float64 `json:"marketamount"`                                 // 市值
 	LastPrice       float64 `json:"lastprice"`                                    // 最新价
 	Tradeproperty   int32   `json:"tradeproperty"`                                // 交易属性
+	REFGOODSID      int32   `json:"refgoodsid"  xorm:"'REFGOODSID'"`              // 参考商品ID
+	REFGOODSCODE    string  `json:"refgoodscode"  xorm:"'REFGOODSCODE'"`          // 参考商品代码
 }
 
 // QueryTradePosition 持仓汇总查询(合约市场)
@@ -127,15 +129,19 @@ func GetTradePosition(accIds string, tradeModes string) (rst []QueryTradePositio
 		Marketid             int32   `json:"marketid"  xorm:"'MARKETID'"`               // 市场ID
 		Trademode            int32   `json:"trademode"  xorm:"'TRADEMODE'"`             // 交易模式
 		QTYDECIMALPLACE      int32   `json:"qtydecimalplace"  xorm:"'QTYDECIMALPLACE'"` // 成交量小数位
+		REFGOODSID           int32   `json:"refgoodsid"  xorm:"'REFGOODSID'"`           // 参考商品ID
+		REFGOODSCODE         string  `json:"refgoodscode"  xorm:"'REFGOODSCODE'"`       // 参考商品代码
 	}
 	datas := make([]tradePosition, 0)
 	engine := db.GetEngine()
 	// ORACLE好像在JOIN里不支持别名功能(在XORM中)
 	s := engine.Table("TRADEPOSITION").
 		Join("LEFT", "GOODS", "TRADEPOSITION.GOODSID = GOODS.GOODSID").
+		Join("LEFT", "GOODS G2", "GOODS.REFGOODSID = G2.GOODSID").
 		Join("LEFT", "MARKET", "GOODS.MARKETID = MARKET.MARKETID").
 		Join("LEFT", "ENUMDICITEM", "GOODS.GOODUNITID = ENUMDICITEM.ENUMITEMNAME and ENUMDICITEM.ENUMDICCODE = 'goodsunit'").
-		Select("TRADEPOSITION.*, GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.CURRENCYID, GOODS.GOODUNITID,GOODS.QTYDECIMALPLACE, ENUMDICITEM.ENUMDICNAME as GOODUNIT, GOODS.AGREEUNIT, GOODS.DECIMALPLACE, MARKET.MARKETID, MARKET.TRADEMODE").
+		Select("TRADEPOSITION.*, GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.CURRENCYID, GOODS.GOODUNITID,GOODS.QTYDECIMALPLACE, G2.REFGOODSID, G2.REFGOODSCODE, " +
+			"ENUMDICITEM.ENUMDICNAME as GOODUNIT, GOODS.AGREEUNIT, GOODS.DECIMALPLACE, MARKET.MARKETID, MARKET.TRADEMODE").
 		Where(fmt.Sprintf(`TRADEPOSITION.ACCOUNTID in (%s)`, accIds))
 	if len(tradeModes) > 0 {
 		s = s.And(fmt.Sprintf(`MARKET.TRADEMODE in (%s)`, tradeModes))
@@ -193,6 +199,8 @@ func GetTradePosition(accIds string, tradeModes string) (rst []QueryTradePositio
 				// json -> struct
 				_ = json.Unmarshal(jsonBytes, &tradePosition)
 				tradePosition.Tradeproperty = v.Tradeproperty
+				tradePosition.REFGOODSID = v.REFGOODSID
+				tradePosition.REFGOODSCODE = v.REFGOODSCODE
 				tradePosition.BuyOrSell = 0
 				tradePosition.PositionQTY = c.CovertQty(v.Buypositionqty)
 				tradePosition.HolderAmount = v.Buyholderamount
@@ -233,6 +241,8 @@ func GetTradePosition(accIds string, tradeModes string) (rst []QueryTradePositio
 				// json -> struct
 				_ = json.Unmarshal(jsonBytes, &tradePosition)
 				tradePosition.Tradeproperty = v.Tradeproperty
+				tradePosition.REFGOODSID = v.REFGOODSID
+				tradePosition.REFGOODSCODE = v.REFGOODSCODE
 				tradePosition.BuyOrSell = 1
 				tradePosition.PositionQTY = c.CovertQty(v.Sellpositionqty)
 				tradePosition.HolderAmount = v.Sellholderamount

+ 14 - 2
controllers/other/logfilelist.go

@@ -25,7 +25,9 @@ func LogList(c *gin.Context) {
 
 	const templateText = `
 <h1>日志文件列表</h1>
-{{.db}}
+oracle : {{.db}} <br>
+mysql  : {{.mysql}} <br>
+redis  : {{.redis}} <br>
 <p>------------------------</p>
 {{.data}}
 <p>------------------------</p>
@@ -37,6 +39,15 @@ func LogList(c *gin.Context) {
 		config.SerCfg.DbCfg.DbAddress,
 		config.SerCfg.DbCfg.DbPort,
 		config.SerCfg.DbCfg.DbName)
+
+	mysql := fmt.Sprintf("%s/***@%s:%v/%s",
+		config.SerCfg.MySQLCfg.Username,
+		config.SerCfg.MySQLCfg.Host,
+		config.SerCfg.MySQLCfg.Port,
+		config.SerCfg.MySQLCfg.DBName)
+
+	redis := fmt.Sprintf("%s:%v", config.SerCfg.RedisCfg.Address, config.SerCfg.RedisCfg.Port)
+
 	if d, err := ioutil.ReadDir(path); err == nil {
 		for _, v := range d {
 			if !v.IsDir() {
@@ -49,7 +60,8 @@ func LogList(c *gin.Context) {
 		}
 		str := strings.Join(sFile, "\n<br>")
 		if tmpl, err := template.New("index").Parse(templateText); err == nil {
-			_ = tmpl.Execute(c.Writer, gin.H{"data": template.HTML(str), "db": template.HTML(db)})
+			_ = tmpl.Execute(c.Writer, gin.H{"data": template.HTML(str), "db": template.HTML(db),
+				"mysql": template.HTML(mysql), "redis": template.HTML(redis)})
 		} else {
 			c.String(400, "index err.")
 		}

+ 23 - 0
controllers/tradexx/qryTradexx.go

@@ -32,3 +32,26 @@ func QueryTradeHolderDetail(c *gin.Context) {
 	a.DoBindReq(&m)
 	a.DoGetDataI(&m)
 }
+
+/* 暂时不启用, 未完成获取行情计算浮动盈亏
+// QueryTradePosition
+// @Summary 查询持仓汇总2
+// @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 /Order/QueryTradePosition2 [get]
+// @Tags 通用单据
+func QueryTradePosition(c *gin.Context) {
+	a := app.GinUtils{Gin: app.Gin{C: c}}
+	m := models.TradePosition{BUYORSELL: -1}
+	a.DoBindReq(&m)
+	a.DoGetDataI(&m)
+}
+*/

+ 79 - 0
docs/docs.go

@@ -7734,6 +7734,77 @@ var doc = `{
                 }
             }
         },
+        "/Order/QueryTradePosition2": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "通用单据"
+                ],
+                "summary": "查询持仓汇总2",
+                "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"
+                        }
+                    }
+                }
+            }
+        },
         "/Qhj/QueryAccountInOutApply": {
             "get": {
                 "security": [
@@ -37135,6 +37206,14 @@ var doc = `{
                     "description": "成交量小数位",
                     "type": "integer"
                 },
+                "refgoodscode": {
+                    "description": "参考商品代码",
+                    "type": "string"
+                },
+                "refgoodsid": {
+                    "description": "参考商品ID",
+                    "type": "integer"
+                },
                 "tnqty": {
                     "description": "T+N冻结总量",
                     "type": "number"

+ 79 - 0
docs/swagger.json

@@ -7718,6 +7718,77 @@
                 }
             }
         },
+        "/Order/QueryTradePosition2": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "通用单据"
+                ],
+                "summary": "查询持仓汇总2",
+                "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"
+                        }
+                    }
+                }
+            }
+        },
         "/Qhj/QueryAccountInOutApply": {
             "get": {
                 "security": [
@@ -37119,6 +37190,14 @@
                     "description": "成交量小数位",
                     "type": "integer"
                 },
+                "refgoodscode": {
+                    "description": "参考商品代码",
+                    "type": "string"
+                },
+                "refgoodsid": {
+                    "description": "参考商品ID",
+                    "type": "integer"
+                },
                 "tnqty": {
                     "description": "T+N冻结总量",
                     "type": "number"

+ 51 - 0
docs/swagger.yaml

@@ -17426,6 +17426,12 @@ definitions:
       qtydecimalplace:
         description: 成交量小数位
         type: integer
+      refgoodscode:
+        description: 参考商品代码
+        type: string
+      refgoodsid:
+        description: 参考商品ID
+        type: integer
       tnqty:
         description: T+N冻结总量
         type: number
@@ -23406,6 +23412,51 @@ paths:
       summary: 持仓汇总查询(合约市场)
       tags:
       - 通用单据
+  /Order/QueryTradePosition2:
+    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: 查询持仓汇总2
+      tags:
+      - 通用单据
   /Qhj/QueryAccountInOutApply:
     get:
       parameters:

+ 27 - 15
models/tradexx.go

@@ -40,26 +40,31 @@ type TradeAccountEx struct {
 
 // TradePosition 持仓汇总
 type TradePosition struct {
-	ACCOUNTID      int64    `json:"accountid"  xorm:"'ACCOUNTID'"`           // 账户id
-	GOODSID        int32    `json:"goodsid"  xorm:"'GOODSID'"`               // 商品id
-	HOLDERTYPE     int32    `json:"holdertype"  xorm:"'HOLDERTYPE'"`         // 持仓类别 - 1:单边持仓 2:双边持仓
-	TRADEPROPERTY  int32    `json:"tradeproperty"  xorm:"'TRADEPROPERTY'"`   // 交易属性
-	BUYORSELL      int32    `json:"buyorsell"  xorm:"'BUYORSELL'"`           // 买卖方向 0-买 1-卖
-	USEDMARGIN     SFLOAT64 `json:"usedmargin"  xorm:"'USEDMARGIN'"`         // 占用保证金
-	ORIQTY         SFLOAT64 `json:"oriqty"  xorm:"'ORIQTY'"`                 // 期初持仓数量
-	QTY            SFLOAT64 `json:"qty"  xorm:"'QTY'"`                       // 持仓数量
-	FROZENQTY      SFLOAT64 `json:"frozenqty"  xorm:"'FROZENQTY'"`           // 冻结数量
-	OTHERFROZENQTY SFLOAT64 `json:"otherfrozenqty"  xorm:"'OTHERFROZENQTY'"` // 其它冻结数量
-	CUROPENQTY     SFLOAT64 `json:"curopenqty"  xorm:"'CUROPENQTY'"`         // 今日开仓数量
-	CURCLOSEQTY    SFLOAT64 `json:"curcloseqty"  xorm:"'CURCLOSEQTY'"`       // 今日平仓数量
-	ORIAMOUNT      SFLOAT64 `json:"oriamount"  xorm:"'ORIAMOUNT'"`           // 期初持仓金额
-	AMOUNT         SFLOAT64 `json:"amount"  xorm:"'AMOUNT'"`                 // 持仓金额
+	ACCOUNTID      int64    `json:"accountid"  xorm:"'ACCOUNTID'"`                  // 账户id
+	GOODSID        int32    `json:"goodsid"  xorm:"'GOODSID'" form:"goodsid"`       // 商品id
+	HOLDERTYPE     int32    `json:"holdertype"  xorm:"'HOLDERTYPE'"`                // 持仓类别 - 1:单边持仓 2:双边持仓
+	TRADEPROPERTY  int32    `json:"tradeproperty"  xorm:"'TRADEPROPERTY'"`          // 交易属性
+	BUYORSELL      int32    `json:"buyorsell"  xorm:"'BUYORSELL'" form:"buyorsell"` // 买卖方向 0-买 1-卖
+	USEDMARGIN     SFLOAT64 `json:"usedmargin"  xorm:"'USEDMARGIN'"`                // 占用保证金
+	ORIQTY         SFLOAT64 `json:"oriqty"  xorm:"'ORIQTY'"`                        // 期初持仓数量
+	QTY            SFLOAT64 `json:"qty"  xorm:"'QTY'"`                              // 持仓数量
+	FROZENQTY      SFLOAT64 `json:"frozenqty"  xorm:"'FROZENQTY'"`                  // 冻结数量
+	OTHERFROZENQTY SFLOAT64 `json:"otherfrozenqty"  xorm:"'OTHERFROZENQTY'"`        // 其它冻结数量
+	CUROPENQTY     SFLOAT64 `json:"curopenqty"  xorm:"'CUROPENQTY'"`                // 今日开仓数量
+	CURCLOSEQTY    SFLOAT64 `json:"curcloseqty"  xorm:"'CURCLOSEQTY'"`              // 今日平仓数量
+	ORIAMOUNT      SFLOAT64 `json:"oriamount"  xorm:"'ORIAMOUNT'"`                  // 期初持仓金额
+	AMOUNT         SFLOAT64 `json:"amount"  xorm:"'AMOUNT'"`                        // 持仓金额
 	TradeGoodsEx   `xorm:"extends"`
 	TradeAccountEx `xorm:"extends"`
 
 	HOLDERPRICE SFLOAT64 `json:"holderprice"` // 持仓均价 = 持仓金额 / 持仓数量 / 合约剩数 保留3位小数
 	LASTPRICE   SFLOAT64 `json:"lastprice"`   // 最新价 从盘面上获取
 	POSTIONPL   SFLOAT64 `json:"postionpl"`   // 持仓盈亏(浮动盈亏)
+	ENABLEQTY   SFLOAT64 `json:"enableqty"`   // 可用数量
+
+	FtAccountIDs string `json:"-" form:"accids"`     // 资金账号,逗号隔开
+	FtTradeMode  string `json:"-" form:"trademodes"` // 交易模式筛选, 逗号隔开
+	FtMarketIDs  string `json:"-" form:"marketids"`  // 市场id, 逗号隔开
 }
 
 func (r *TradePosition) calc() {
@@ -68,9 +73,10 @@ func (r *TradePosition) calc() {
 			vl[i].Power10(n * -1)
 		}
 	}
+	r.ENABLEQTY = r.QTY - r.FROZENQTY - r.OTHERFROZENQTY
 	// 数量 按成交量小数位缩小
 	fNegativePower10(r.QTYDECIMALPLACE, &r.ORIQTY, &r.QTY, &r.FROZENQTY,
-		&r.OTHERFROZENQTY, &r.CUROPENQTY, &r.CURCLOSEQTY)
+		&r.OTHERFROZENQTY, &r.CUROPENQTY, &r.CURCLOSEQTY, &r.ENABLEQTY)
 	if r.AGREEUNIT > 1e-8 {
 		r.HOLDERPRICE = r.AMOUNT / r.QTY / SFLOAT64(r.AGREEUNIT)
 		r.HOLDERPRICE.Round(3)
@@ -155,6 +161,12 @@ select k.*, t1.*, t2.*
     on k.accountid = t2.accountid
  where 1 = 1
 `
+	sqlId.AndEx("utmp.userid", r.USERID, r.USERID > 0)
+	sqlId.AndEx("t.goodsid", r.GOODSID, r.GOODSID > 0)
+	sqlId.AndEx("t.BUYORSELL", r.BUYORSELL, r.BUYORSELL != -1)
+	sqlId.JoinEx(r.FtTradeMode != "", fmt.Sprintf(" and t1.trademode in(%v)", r.FtTradeMode))
+	sqlId.JoinEx(r.FtMarketIDs != "", fmt.Sprintf(" and t1.marketid in(%v)", r.FtMarketIDs))
+	sqlId.JoinEx(r.FtAccountIDs != "", fmt.Sprintf(" and k.accountid in(%v)", r.FtAccountIDs))
 	return sqlId.String()
 }
 

+ 1 - 0
routers/router.go

@@ -159,6 +159,7 @@ func InitRouter() *gin.Engine {
 		orderR.GET("/QueryHisTradeDetail", order.QueryHisTradeDetail)
 
 		orderR.GET("/QueryTradeHolderDetail", tradexx.QueryTradeHolderDetail)
+		orderR.GET("/QueryTradePosition2", tradexx.QueryTradePosition)
 	}
 	// ************************ 通用交易 ************************
 	tradeR := apiR.Group("Trade")