Browse Source

“查询交易端菜单” 接口增加外部交易所列表功能

Simon Zhou 5 năm trước cách đây
mục cha
commit
db539925f4
5 tập tin đã thay đổi với 234 bổ sung17 xóa
  1. 2 2
      config/config.xml
  2. 44 12
      controllers/common/table.go
  3. 69 1
      docs/docs.go
  4. 69 1
      docs/swagger.json
  5. 50 1
      docs/swagger.yaml

+ 2 - 2
config/config.xml

@@ -16,12 +16,12 @@
         <DbAddress value="192.168.31.117"/>
         <DbName    value="orcl"/>
         <DbPort    value="1521"/>
-        <DbUser    value="mtp2_test104"/>
+        <DbUser    value="mtp2_test118"/>
         <DbPwd     value="muchinfo"/>
     </DbSetting>
 
     <RedisSetting>
-        <Address   value="192.168.31.104"/>
+        <Address   value="192.168.31.118"/>
         <Port      value="5007"/>
         <Timeout   value="3"/>
         <ConnNum   value="1"/>

+ 44 - 12
controllers/common/table.go

@@ -32,12 +32,13 @@ type QuotePrimaryMenu struct {
 
 // QuoteSecondaryMenu 报价牌二级分类菜单
 type QuoteSecondaryMenu struct {
-	Index          int    `json:"index"`          // 序号
-	MarketID       int    `json:"marketid"`       // 市场ID
-	TradeMode      int    `json:"trademode"`      // 交易模式
-	MenuTitle      string `json:"menutitle"`      // 菜单标题(市场名称或外部交易所名称)
-	GoodsGroupID   int    `json:"goodsgroupid"`   // 商品组ID
-	ExExchangeCode string `json:"exexchangecode"` // 外部交易所代码
+	Index          int    `json:"index"`                                  // 序号
+	MarketID       int    `json:"marketid"`                               // 市场ID
+	TradeMode      int    `json:"trademode"`                              // 交易模式
+	MenuTitle      string `json:"menutitle" xorm:"'ExExchangeName'"`      // 菜单标题(市场名称或外部交易所名称)
+	GoodsGroupIDs  []int  `json:"goodsgroupids"`                          // 商品组ID列表
+	ExExchangeID   int    `json:"exexchangeid" xorm:"'ExExchangeID'"`     // 外部交易所ID
+	ExExchangeCode string `json:"exexchangecode" xorm:"'ExExchangeCode'"` // 外部交易所代码
 }
 
 // QueryTraderMenu 查询交易端菜单
@@ -45,7 +46,7 @@ type QuoteSecondaryMenu struct {
 // @Produce json
 // @Security ApiKeyAuth
 // @Param loginid query int true "登录账号"
-// @Success 200 {object} app.Response
+// @Success 200 {object} QuotePrimaryMenu
 // @Failure 500 {object} app.Response
 // @Router /Common/QueryTraderMenu [get]
 // @Tags 通用
@@ -120,13 +121,13 @@ func getMenu(loginID int) ([]QuotePrimaryMenu, error) {
 		quotePrimaryMenu.TradeModes = v.Remark
 
 		// 构建二级子菜单对象
-		// 获取目标交易模式的市场信息
-		markets := make([]models.Market, 0)
 		marketIDsStr := utils.JoinItoString(marketIDs, ",")
-		if err := engine.Where(fmt.Sprintf(`TradeMode in (%s) and MarketID in (%s)`, quotePrimaryMenu.TradeModes, marketIDsStr)).Find(&markets); err != nil {
-			return nil, err
-		}
 		if quotePrimaryMenu.SubTitleType == 0 {
+			// 获取目标交易模式的市场信息
+			markets := make([]models.Market, 0)
+			if err := engine.Where(fmt.Sprintf(`TradeMode in (%s) and MarketID in (%s)`, quotePrimaryMenu.TradeModes, marketIDsStr)).Find(&markets); err != nil {
+				return nil, err
+			}
 			// 使用市场名称
 			for mi, mv := range markets {
 				quoteSecondaryMenu := QuoteSecondaryMenu{
@@ -139,6 +140,37 @@ func getMenu(loginID int) ([]QuotePrimaryMenu, error) {
 			}
 		} else {
 			// 使用外部交易所名称
+			quoteSecondaryMenus := make([]QuoteSecondaryMenu, 0)
+			sql := fmt.Sprintf(`select distinct
+									e.autoid ExExchangeID,
+									e.ExExchangeName,
+									e.ExExchangeCode 
+								from ExternalExchange e
+								inner join goodsgroup g  on g.exexchangeid = e.autoid
+								inner join Market m on g.marketid = m.marketid
+								where m.trademode in (%s) and m.marketid in (%s)`, quotePrimaryMenu.TradeModes, marketIDsStr)
+			if err := engine.SQL(sql).Find(&quoteSecondaryMenus); err != nil {
+				return nil, err
+			}
+			// 获取外部交易所对应的商品组信息
+			for ei, ev := range quoteSecondaryMenus {
+				q := &quoteSecondaryMenus[ei]
+				q.Index = ei
+				// 商品组列表
+				goodsgroups := make([]models.Goodsgroup, 0)
+				if err := engine.Where("Exexchangeid = ?", ev.ExExchangeID).Find(&goodsgroups); err != nil {
+					return nil, err
+				}
+				marketID := 0
+				var goodsGroupIDs []int
+				for _, gv := range goodsgroups {
+					marketID = int(gv.Marketid)
+					goodsGroupIDs = append(goodsGroupIDs, int(gv.Goodsgroupid))
+				}
+				q.MarketID = marketID
+				q.GoodsGroupIDs = goodsGroupIDs
+			}
+			quotePrimaryMenu.SubMenus = quoteSecondaryMenus
 		}
 
 		rst = append(rst, quotePrimaryMenu)

+ 69 - 1
docs/docs.go

@@ -396,7 +396,7 @@ var doc = `{
                     "200": {
                         "description": "OK",
                         "schema": {
-                            "$ref": "#/definitions/app.Response"
+                            "$ref": "#/definitions/common.QuotePrimaryMenu"
                         }
                     },
                     "500": {
@@ -667,6 +667,74 @@ var doc = `{
                 }
             }
         },
+        "common.QuotePrimaryMenu": {
+            "type": "object",
+            "properties": {
+                "index": {
+                    "description": "序号",
+                    "type": "integer"
+                },
+                "key": {
+                    "description": "键名",
+                    "type": "string"
+                },
+                "name": {
+                    "description": "菜单名称",
+                    "type": "string"
+                },
+                "submenus": {
+                    "description": "子菜单",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/common.QuoteSecondaryMenu"
+                    }
+                },
+                "titletype": {
+                    "description": "子菜单标题模式:0-市场名称;1-外部交易所名称",
+                    "type": "integer"
+                },
+                "trademodes": {
+                    "description": "包含市场交易类型",
+                    "type": "string"
+                }
+            }
+        },
+        "common.QuoteSecondaryMenu": {
+            "type": "object",
+            "properties": {
+                "exexchangecode": {
+                    "description": "外部交易所代码",
+                    "type": "string"
+                },
+                "exexchangeid": {
+                    "description": "外部交易所ID",
+                    "type": "integer"
+                },
+                "goodsgroupids": {
+                    "description": "商品组ID列表",
+                    "type": "array",
+                    "items": {
+                        "type": "integer"
+                    }
+                },
+                "index": {
+                    "description": "序号",
+                    "type": "integer"
+                },
+                "marketid": {
+                    "description": "市场ID",
+                    "type": "integer"
+                },
+                "menutitle": {
+                    "description": "菜单标题(市场名称或外部交易所名称)",
+                    "type": "string"
+                },
+                "trademode": {
+                    "description": "交易模式",
+                    "type": "integer"
+                }
+            }
+        },
         "cptrade.Cptradepositioncancel": {
             "type": "object",
             "required": [

+ 69 - 1
docs/swagger.json

@@ -380,7 +380,7 @@
                     "200": {
                         "description": "OK",
                         "schema": {
-                            "$ref": "#/definitions/app.Response"
+                            "$ref": "#/definitions/common.QuotePrimaryMenu"
                         }
                     },
                     "500": {
@@ -651,6 +651,74 @@
                 }
             }
         },
+        "common.QuotePrimaryMenu": {
+            "type": "object",
+            "properties": {
+                "index": {
+                    "description": "序号",
+                    "type": "integer"
+                },
+                "key": {
+                    "description": "键名",
+                    "type": "string"
+                },
+                "name": {
+                    "description": "菜单名称",
+                    "type": "string"
+                },
+                "submenus": {
+                    "description": "子菜单",
+                    "type": "array",
+                    "items": {
+                        "$ref": "#/definitions/common.QuoteSecondaryMenu"
+                    }
+                },
+                "titletype": {
+                    "description": "子菜单标题模式:0-市场名称;1-外部交易所名称",
+                    "type": "integer"
+                },
+                "trademodes": {
+                    "description": "包含市场交易类型",
+                    "type": "string"
+                }
+            }
+        },
+        "common.QuoteSecondaryMenu": {
+            "type": "object",
+            "properties": {
+                "exexchangecode": {
+                    "description": "外部交易所代码",
+                    "type": "string"
+                },
+                "exexchangeid": {
+                    "description": "外部交易所ID",
+                    "type": "integer"
+                },
+                "goodsgroupids": {
+                    "description": "商品组ID列表",
+                    "type": "array",
+                    "items": {
+                        "type": "integer"
+                    }
+                },
+                "index": {
+                    "description": "序号",
+                    "type": "integer"
+                },
+                "marketid": {
+                    "description": "市场ID",
+                    "type": "integer"
+                },
+                "menutitle": {
+                    "description": "菜单标题(市场名称或外部交易所名称)",
+                    "type": "string"
+                },
+                "trademode": {
+                    "description": "交易模式",
+                    "type": "integer"
+                }
+            }
+        },
         "cptrade.Cptradepositioncancel": {
             "type": "object",
             "required": [

+ 50 - 1
docs/swagger.yaml

@@ -9,6 +9,55 @@ definitions:
       msg:
         type: string
     type: object
+  common.QuotePrimaryMenu:
+    properties:
+      index:
+        description: 序号
+        type: integer
+      key:
+        description: 键名
+        type: string
+      name:
+        description: 菜单名称
+        type: string
+      submenus:
+        description: 子菜单
+        items:
+          $ref: '#/definitions/common.QuoteSecondaryMenu'
+        type: array
+      titletype:
+        description: 子菜单标题模式:0-市场名称;1-外部交易所名称
+        type: integer
+      trademodes:
+        description: 包含市场交易类型
+        type: string
+    type: object
+  common.QuoteSecondaryMenu:
+    properties:
+      exexchangecode:
+        description: 外部交易所代码
+        type: string
+      exexchangeid:
+        description: 外部交易所ID
+        type: integer
+      goodsgroupids:
+        description: 商品组ID列表
+        items:
+          type: integer
+        type: array
+      index:
+        description: 序号
+        type: integer
+      marketid:
+        description: 市场ID
+        type: integer
+      menutitle:
+        description: 菜单标题(市场名称或外部交易所名称)
+        type: string
+      trademode:
+        description: 交易模式
+        type: integer
+    type: object
   cptrade.Cptradepositioncancel:
     properties:
       accountid:
@@ -1316,7 +1365,7 @@ paths:
         "200":
           description: OK
           schema:
-            $ref: '#/definitions/app.Response'
+            $ref: '#/definitions/common.QuotePrimaryMenu'
         "500":
           description: Internal Server Error
           schema: