Sfoglia il codice sorgente

增加查询企业风管期货主力、次主力商品信息接口

zhou.xiaoning 4 anni fa
parent
commit
a8ec34d6dc
7 ha cambiato i file con 267 aggiunte e 6 eliminazioni
  1. 6 6
      config/config.xml
  2. 39 0
      controllers/ermcp/qryGoods.go
  3. 71 0
      docs/docs.go
  4. 71 0
      docs/swagger.json
  5. 47 0
      docs/swagger.yaml
  6. 31 0
      models/ermcpGoods.go
  7. 2 0
      routers/router.go

+ 6 - 6
config/config.xml

@@ -13,11 +13,11 @@
     <DbAddress value="192.168.31.117"/>
     <DbName value="orcl"/>
     <DbPort value="1521"/>
-    <DbUser value="mtp2_test114"/>
+    <DbUser value="mtp2_test211"/>
     <DbPwd value="muchinfo"/>
   </DbSetting>
   <RedisSetting>
-    <Address value="192.168.31.114"/>
+    <Address value="192.168.30.211"/>
     <Port value="5007"/>
     <Timeout value="3"/>
     <ConnNum value="1"/>
@@ -25,11 +25,11 @@
     <Pwd value=""/>
   </RedisSetting>
   <MqSetting>
-    <Url value="amqp://guest:guest@192.168.31.114:5020/test"/>
+    <Url value="amqp://guest:guest@192.168.30.211:5020/test"/>
     <Exchange value="entry"/>
   </MqSetting>
   <MongoDBSetting>
-    <HostName value="192.168.31.114"/>
+    <HostName value="192.168.30.211"/>
     <Port value="5025"/>
     <DBName value="HistoryQuote"/>
     <Username value="quote_test01"/>
@@ -38,8 +38,8 @@
   <MySQLSetting>
     <Host value="192.168.30.140"/>
     <Port value="3306"/>
-    <DBName value="historyquote_test114"/>
-    <Username value="quote_test114"/>
+    <DBName value="historyquote_test211"/>
+    <Username value="quote_test211"/>
     <Password value="123456"/>
   </MySQLSetting>
 </Configuration>

+ 39 - 0
controllers/ermcp/qryGoods.go

@@ -48,3 +48,42 @@ func GetErmcpGoods(c *gin.Context) {
 	logger.GetLogger().Debugln("GetErmcpGoods successed: %v", goodses)
 	appG.Response(http.StatusOK, e.SUCCESS, goodses)
 }
+
+// GetErmcpGoodsSortByPositionReq 查询企业风管期货主力、次主力商品信息请求参数
+type GetErmcpGoodsSortByPositionReq struct {
+	SortIndex string `form:"sortIndex"`
+}
+
+// GetErmcpGoodsSortByPosition 查询企业风管期货主力、次主力商品信息
+// @Summary 查询企业风管期货主力、次主力商品信息
+// @Produce json
+// @Security ApiKeyAuth
+// @Param sortIndex query string false "主力: 1; 次主力: 2; 主力+次主力:1,2"
+// @Success 200 {object} models.Goodssortbypreposition
+// @Failure 500 {object} app.Response
+// @Router /Ermcp/GetErmcpGoodsSortByPosition [get]
+// @Tags 企业风险管理(app)
+func GetErmcpGoodsSortByPosition(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	// 获取请求参数
+	var req GetErmcpGoodsSortByPositionReq
+	if err := appG.C.ShouldBindQuery(&req); err != nil {
+		logger.GetLogger().Errorf("GetErmcpGoodsSortByPosition failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	// 获取数据
+	goodses, err := models.GetGoodsSortByPrePositions(req.SortIndex)
+	if err != nil {
+		// 查询失败
+		logger.GetLogger().Errorf("GetErmcpGoodsSortByPosition failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		return
+	}
+
+	// 查询成功返回
+	logger.GetLogger().Debugln("GetErmcpGoodsSortByPosition successed: %v", goodses)
+	appG.Response(http.StatusOK, e.SUCCESS, goodses)
+}

+ 71 - 0
docs/docs.go

@@ -828,6 +828,44 @@ var doc = `{
                 }
             }
         },
+        "/Ermcp/GetErmcpGoodsSortByPosition": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "企业风险管理(app)"
+                ],
+                "summary": "查询企业风管期货主力、次主力商品信息",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "主力: 1; 次主力: 2; 主力+次主力:1,2",
+                        "name": "sortIndex",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/models.Goodssortbypreposition"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Ermcp/GetErmcpRoleFuncMenuLists": {
             "get": {
                 "security": [
@@ -14276,6 +14314,39 @@ var doc = `{
                 }
             }
         },
+        "models.Goodssortbypreposition": {
+            "type": "object",
+            "required": [
+                "goodscode",
+                "tradedate"
+            ],
+            "properties": {
+                "goodscode": {
+                    "description": "合约代码 - 易盛接口:合约代码=品种代码+合约代码",
+                    "type": "string"
+                },
+                "goodsgroupcode": {
+                    "description": "品种代码",
+                    "type": "string"
+                },
+                "prepositionqty": {
+                    "description": "昨持仓量",
+                    "type": "integer"
+                },
+                "sortindex": {
+                    "description": "排序",
+                    "type": "integer"
+                },
+                "tradedate": {
+                    "description": "交易日",
+                    "type": "string"
+                },
+                "updatetime": {
+                    "description": "更新时间",
+                    "type": "string"
+                }
+            }
+        },
         "models.HsbyBuyMyPayOrder": {
             "type": "object",
             "required": [

+ 71 - 0
docs/swagger.json

@@ -812,6 +812,44 @@
                 }
             }
         },
+        "/Ermcp/GetErmcpGoodsSortByPosition": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "企业风险管理(app)"
+                ],
+                "summary": "查询企业风管期货主力、次主力商品信息",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "主力: 1; 次主力: 2; 主力+次主力:1,2",
+                        "name": "sortIndex",
+                        "in": "query"
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/models.Goodssortbypreposition"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/Ermcp/GetErmcpRoleFuncMenuLists": {
             "get": {
                 "security": [
@@ -14260,6 +14298,39 @@
                 }
             }
         },
+        "models.Goodssortbypreposition": {
+            "type": "object",
+            "required": [
+                "goodscode",
+                "tradedate"
+            ],
+            "properties": {
+                "goodscode": {
+                    "description": "合约代码 - 易盛接口:合约代码=品种代码+合约代码",
+                    "type": "string"
+                },
+                "goodsgroupcode": {
+                    "description": "品种代码",
+                    "type": "string"
+                },
+                "prepositionqty": {
+                    "description": "昨持仓量",
+                    "type": "integer"
+                },
+                "sortindex": {
+                    "description": "排序",
+                    "type": "integer"
+                },
+                "tradedate": {
+                    "description": "交易日",
+                    "type": "string"
+                },
+                "updatetime": {
+                    "description": "更新时间",
+                    "type": "string"
+                }
+            }
+        },
         "models.HsbyBuyMyPayOrder": {
             "type": "object",
             "required": [

+ 47 - 0
docs/swagger.yaml

@@ -5446,6 +5446,30 @@ definitions:
     - goodsgroupstatus
     - marketid
     type: object
+  models.Goodssortbypreposition:
+    properties:
+      goodscode:
+        description: 合约代码 - 易盛接口:合约代码=品种代码+合约代码
+        type: string
+      goodsgroupcode:
+        description: 品种代码
+        type: string
+      prepositionqty:
+        description: 昨持仓量
+        type: integer
+      sortindex:
+        description: 排序
+        type: integer
+      tradedate:
+        description: 交易日
+        type: string
+      updatetime:
+        description: 更新时间
+        type: string
+    required:
+    - goodscode
+    - tradedate
+    type: object
   models.HsbyBuyMyPayOrder:
     properties:
       agreeunit:
@@ -10440,6 +10464,29 @@ paths:
       summary: 查询企业风管期货商品信息
       tags:
       - 企业风险管理(app)
+  /Ermcp/GetErmcpGoodsSortByPosition:
+    get:
+      parameters:
+      - description: '主力: 1; 次主力: 2; 主力+次主力:1,2'
+        in: query
+        name: sortIndex
+        type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/models.Goodssortbypreposition'
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 查询企业风管期货主力、次主力商品信息
+      tags:
+      - 企业风险管理(app)
   /Ermcp/GetErmcpRoleFuncMenuLists:
     get:
       parameters:

+ 31 - 0
models/ermcpGoods.go

@@ -8,6 +8,22 @@ import (
 	"time"
 )
 
+// Goodssortbypreposition 合约昨持仓排序表 - 同一品种内按昨持仓量倒排序
+// 行情服务清盘前生成此表,供交易服务风控规则使用;生成前先删除此表数据;
+type Goodssortbypreposition struct {
+	Tradedate      string    `json:"tradedate"  xorm:"'TRADEDATE'" binding:"required"` // 交易日
+	Goodscode      string    `json:"goodscode"  xorm:"'GOODSCODE'" binding:"required"` // 合约代码 - 易盛接口:合约代码=品种代码+合约代码
+	Goodsgroupcode string    `json:"goodsgroupcode"  xorm:"'GOODSGROUPCODE'"`          // 品种代码
+	Sortindex      int64     `json:"sortindex"  xorm:"'SORTINDEX'"`                    // 排序
+	Prepositionqty int64     `json:"prepositionqty"  xorm:"'PREPOSITIONQTY'"`          // 昨持仓量
+	Updatetime     time.Time `json:"updatetime"  xorm:"'UPDATETIME'"`                  // 更新时间
+}
+
+// TableName is GOODSSORTBYPREPOSITION
+func (Goodssortbypreposition) TableName() string {
+	return "GOODSSORTBYPREPOSITION"
+}
+
 // GetErmcpGoodses 企业风管专用获取商品信息的方法
 func GetErmcpGoodses(lastUpdateTime string) ([]Goods, error) {
 	engine := db.GetEngine()
@@ -46,3 +62,18 @@ func GetGoodsLastUpdateTime() (*time.Time, error) {
 
 	return &lastUpdateTimes, nil
 }
+
+// GetGoodsSortByPrePositions 获取查询主力+次主力商品
+func GetGoodsSortByPrePositions(sortIndex string) ([]Goodssortbypreposition, error) {
+	rst := make([]Goodssortbypreposition, 0)
+	session := db.GetEngine().Table("GOODSSORTBYPREPOSITION T")
+	if len(sortIndex) > 0 {
+		session = session.Where(fmt.Sprintf("T.SORTINDEX in (%s)", sortIndex))
+	}
+	session = session.Asc("T.SORTINDEX")
+	if err := session.Find(&rst); err != nil {
+		return nil, err
+	}
+
+	return rst, nil
+}

+ 2 - 0
routers/router.go

@@ -373,6 +373,8 @@ func InitRouter() *gin.Engine {
 		// 期货相关
 		// 查询企业风管期货商品信息
 		ermcpR.GET("/GetErmcpGoods", ermcp.GetErmcpGoods)
+		// 查询企业风管期货主力、次主力商品信息
+		ermcpR.GET("/GetErmcpGoodsSortByPosition", ermcp.GetErmcpGoodsSortByPosition)
 		// 获取企业风管期货持仓头寸信息
 		ermcpR.GET("/QueryErmcpTradePosition", ermcp.QueryErmcpTradePosition)
 		// 获取企业风管期货委托单信息