Ver código fonte

增加“查询‘我的商品’信息”接口

zhou.xiaoning 5 anos atrás
pai
commit
fb735e1f11
6 arquivos alterados com 344 adições e 19 exclusões
  1. 43 4
      controllers/hsby/hsby.go
  2. 94 3
      docs/docs.go
  3. 94 3
      docs/swagger.json
  4. 66 3
      docs/swagger.yaml
  5. 45 6
      models/hsby.go
  6. 2 0
      routers/router.go

+ 43 - 4
controllers/hsby/hsby.go

@@ -212,8 +212,8 @@ func QueryHsbyGoodsOrderDetails(c *gin.Context) {
 
 // QueryHsbyMyBuyOrderDetailsReq 查询“我的订单”信息请求参数
 type QueryHsbyMyBuyOrderDetailsReq struct {
-	AccountID   int `form:"accountID" binding:"required"`
-	MyBuyStatus int `form:"myBuyStatus"`
+	AccountIDs  string `form:"accountIDs" binding:"required"`
+	MyBuyStatus int    `form:"myBuyStatus"`
 }
 
 // QueryHsbyMyBuyOrderDetails 查询“我的订单”信息
@@ -221,7 +221,7 @@ type QueryHsbyMyBuyOrderDetailsReq struct {
 // @Description 说明: 全部:一二级市场买委托;抢购中:一级市场买摘; 求购中:二级市场买挂; 3:已完成:一二级市场已完成买委托;
 // @Produce json
 // @Security ApiKeyAuth
-// @Param accountID query int true "资金账户"
+// @Param accountIDs query string true "资金账户列表,格式:1,2,3"
 // @Param myBuyStatus query int false "'我的订单'状态, 1:抢购中 2:求购中 3:已完成;不传则为'全部'"
 // @Success 200 {object} models.HybsMyBuyOrderDetail
 // @Failure 500 {object} app.Response
@@ -239,7 +239,7 @@ func QueryHsbyMyBuyOrderDetails(c *gin.Context) {
 	}
 
 	// 获取数据
-	myOrderDetails, err := models.GetHsbyBuyMyOrderDetails(req.AccountID, req.MyBuyStatus)
+	myOrderDetails, err := models.GetHsbyBuyMyOrderDetails(req.AccountIDs, req.MyBuyStatus)
 	if err != nil {
 		// 查询失败
 		logger.GetLogger().Errorf("QueryHsbyMyBuyOrderDetails failed: %s", err.Error())
@@ -256,3 +256,42 @@ func QueryHsbyMyBuyOrderDetails(c *gin.Context) {
 	logger.GetLogger().Debugln("QueryHsbyMyBuyOrderDetails successed: %v", myOrderDetails)
 	appG.Response(http.StatusOK, e.SUCCESS, myOrderDetails)
 }
+
+// QueryHsbyMyGoodsReq 查询“我的商品”请求参数
+type QueryHsbyMyGoodsReq struct {
+	AccountIDs string `form:"accountIDs" binding:"required"`
+}
+
+// QueryHsbyMyGoods 查询“我的商品”信息
+// @Summary 查询“我的商品”信息
+// @Produce json
+// @Security ApiKeyAuth
+// @Param accountIDs query string true "资金账户列表,格式:1,2,3"
+// @Success 200 {object} models.HsbyMyGoods
+// @Failure 500 {object} app.Response
+// @Router /HSBY/QueryHsbyMyGoods [get]
+// @Tags 定制【海商报业】
+func QueryHsbyMyGoods(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	// 获取请求参数
+	var req QueryHsbyMyGoodsReq
+	if err := appG.C.ShouldBindQuery(&req); err != nil {
+		logger.GetLogger().Errorf("QueryHsbyMyGoods failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	// 获取数据
+	myGoodses, err := models.GetHsbyMyGoods(req.AccountIDs)
+	if err != nil {
+		// 查询失败
+		logger.GetLogger().Errorf("QueryHsbyMyGoods failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		return
+	}
+
+	// 查询成功返回
+	logger.GetLogger().Debugln("QueryHsbyMyGoods successed: %v", myGoodses)
+	appG.Response(http.StatusOK, e.SUCCESS, myGoodses)
+}

+ 94 - 3
docs/docs.go

@@ -858,9 +858,9 @@ var doc = `{
                 "summary": "查询“我的订单”信息",
                 "parameters": [
                     {
-                        "type": "integer",
-                        "description": "资金账户",
-                        "name": "accountID",
+                        "type": "string",
+                        "description": "资金账户列表,格式:1,2,3",
+                        "name": "accountIDs",
                         "in": "query",
                         "required": true
                     },
@@ -887,6 +887,45 @@ var doc = `{
                 }
             }
         },
+        "/HSBY/QueryHsbyMyGoods": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "定制【海商报业】"
+                ],
+                "summary": "查询“我的商品”信息",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "资金账户列表,格式:1,2,3",
+                        "name": "accountIDs",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/models.HsbyMyGoods"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/HSBY/QueryTopGoods": {
             "get": {
                 "security": [
@@ -3691,6 +3730,53 @@ var doc = `{
                 }
             }
         },
+        "models.HsbyMyGoods": {
+            "type": "object",
+            "required": [
+                "accountid",
+                "goodscode",
+                "goodsid",
+                "goodsname"
+            ],
+            "properties": {
+                "accountid": {
+                    "description": "账号Id",
+                    "type": "integer"
+                },
+                "buycurholderamount": {
+                    "description": "买当前持仓总金额[商品币种]",
+                    "type": "number"
+                },
+                "buycurpositionqty": {
+                    "description": "买当前持仓总数量",
+                    "type": "integer"
+                },
+                "currencysign": {
+                    "description": "货币符号",
+                    "type": "string"
+                },
+                "decimalplace": {
+                    "description": "报价小数位",
+                    "type": "integer"
+                },
+                "goodscode": {
+                    "description": "商品代码(内部)",
+                    "type": "string"
+                },
+                "goodsid": {
+                    "description": "商品Id",
+                    "type": "integer"
+                },
+                "goodsname": {
+                    "description": "商品名称",
+                    "type": "string"
+                },
+                "picurls": {
+                    "description": "介绍图片[多张用逗号分隔]",
+                    "type": "string"
+                }
+            }
+        },
         "models.HsbyTopGoods": {
             "type": "object",
             "required": [
@@ -3751,6 +3837,7 @@ var doc = `{
             "required": [
                 "accountid",
                 "buyorsell",
+                "goodscode",
                 "goodsid",
                 "goodsname",
                 "marketid",
@@ -3780,6 +3867,10 @@ var doc = `{
                     "description": "报价小数位",
                     "type": "integer"
                 },
+                "goodscode": {
+                    "description": "商品代码(内部)",
+                    "type": "string"
+                },
                 "goodsid": {
                     "description": "商品ID",
                     "type": "integer"

+ 94 - 3
docs/swagger.json

@@ -842,9 +842,9 @@
                 "summary": "查询“我的订单”信息",
                 "parameters": [
                     {
-                        "type": "integer",
-                        "description": "资金账户",
-                        "name": "accountID",
+                        "type": "string",
+                        "description": "资金账户列表,格式:1,2,3",
+                        "name": "accountIDs",
                         "in": "query",
                         "required": true
                     },
@@ -871,6 +871,45 @@
                 }
             }
         },
+        "/HSBY/QueryHsbyMyGoods": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "定制【海商报业】"
+                ],
+                "summary": "查询“我的商品”信息",
+                "parameters": [
+                    {
+                        "type": "string",
+                        "description": "资金账户列表,格式:1,2,3",
+                        "name": "accountIDs",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/models.HsbyMyGoods"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/HSBY/QueryTopGoods": {
             "get": {
                 "security": [
@@ -3675,6 +3714,53 @@
                 }
             }
         },
+        "models.HsbyMyGoods": {
+            "type": "object",
+            "required": [
+                "accountid",
+                "goodscode",
+                "goodsid",
+                "goodsname"
+            ],
+            "properties": {
+                "accountid": {
+                    "description": "账号Id",
+                    "type": "integer"
+                },
+                "buycurholderamount": {
+                    "description": "买当前持仓总金额[商品币种]",
+                    "type": "number"
+                },
+                "buycurpositionqty": {
+                    "description": "买当前持仓总数量",
+                    "type": "integer"
+                },
+                "currencysign": {
+                    "description": "货币符号",
+                    "type": "string"
+                },
+                "decimalplace": {
+                    "description": "报价小数位",
+                    "type": "integer"
+                },
+                "goodscode": {
+                    "description": "商品代码(内部)",
+                    "type": "string"
+                },
+                "goodsid": {
+                    "description": "商品Id",
+                    "type": "integer"
+                },
+                "goodsname": {
+                    "description": "商品名称",
+                    "type": "string"
+                },
+                "picurls": {
+                    "description": "介绍图片[多张用逗号分隔]",
+                    "type": "string"
+                }
+            }
+        },
         "models.HsbyTopGoods": {
             "type": "object",
             "required": [
@@ -3735,6 +3821,7 @@
             "required": [
                 "accountid",
                 "buyorsell",
+                "goodscode",
                 "goodsid",
                 "goodsname",
                 "marketid",
@@ -3764,6 +3851,10 @@
                     "description": "报价小数位",
                     "type": "integer"
                 },
+                "goodscode": {
+                    "description": "商品代码(内部)",
+                    "type": "string"
+                },
                 "goodsid": {
                     "description": "商品ID",
                     "type": "integer"

+ 66 - 3
docs/swagger.yaml

@@ -1335,6 +1335,41 @@ definitions:
     - goodsname
     - marketid
     type: object
+  models.HsbyMyGoods:
+    properties:
+      accountid:
+        description: 账号Id
+        type: integer
+      buycurholderamount:
+        description: 买当前持仓总金额[商品币种]
+        type: number
+      buycurpositionqty:
+        description: 买当前持仓总数量
+        type: integer
+      currencysign:
+        description: 货币符号
+        type: string
+      decimalplace:
+        description: 报价小数位
+        type: integer
+      goodscode:
+        description: 商品代码(内部)
+        type: string
+      goodsid:
+        description: 商品Id
+        type: integer
+      goodsname:
+        description: 商品名称
+        type: string
+      picurls:
+        description: 介绍图片[多张用逗号分隔]
+        type: string
+    required:
+    - accountid
+    - goodscode
+    - goodsid
+    - goodsname
+    type: object
   models.HsbyTopGoods:
     properties:
       currency:
@@ -1393,6 +1428,9 @@ definitions:
       decimalplace:
         description: 报价小数位
         type: integer
+      goodscode:
+        description: 商品代码(内部)
+        type: string
       goodsid:
         description: 商品ID
         type: integer
@@ -1441,6 +1479,7 @@ definitions:
     required:
     - accountid
     - buyorsell
+    - goodscode
     - goodsid
     - goodsname
     - marketid
@@ -3662,11 +3701,11 @@ paths:
     get:
       description: 说明: 全部:一二级市场买委托;抢购中:一级市场买摘; 求购中:二级市场买挂; 3:已完成:一二级市场已完成买委托;
       parameters:
-      - description: 资金账户
+      - description: 资金账户列表,格式:1,2,3
         in: query
-        name: accountID
+        name: accountIDs
         required: true
-        type: integer
+        type: string
       - description: '''我的订单''状态, 1:抢购中 2:求购中 3:已完成;不传则为''全部'''
         in: query
         name: myBuyStatus
@@ -3687,6 +3726,30 @@ paths:
       summary: 查询“我的订单”信息
       tags:
       - 定制【海商报业】
+  /HSBY/QueryHsbyMyGoods:
+    get:
+      parameters:
+      - description: 资金账户列表,格式:1,2,3
+        in: query
+        name: accountIDs
+        required: true
+        type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/models.HsbyMyGoods'
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 查询“我的商品”信息
+      tags:
+      - 定制【海商报业】
   /HSBY/QueryTopGoods:
     get:
       description: 说明:查询结果已按Hotindex(景点热度)从大到小排序

+ 45 - 6
models/hsby.go

@@ -301,6 +301,7 @@ type HybsMyBuyOrderDetail struct {
 	Listingselecttype int32     `json:"listingselecttype"  xorm:"'LISTINGSELECTTYPE'"`    // 挂牌点选类型 - 1:挂牌 2:摘牌 3:先摘后挂
 	Orderstatus       int32     `json:"orderstatus"  xorm:"'ORDERSTATUS'"`                // 委托状态 - 1: 委托请求 2:待冻结 3:委托成功 4: 委托失败 5:配对成功 6: 已撤销 7:部分成交 8:已成交 9:部成部撤 10:成交失败 11:已拒绝 12:经过摘牌(先摘后挂专用-先摘后挂已摘过) 13:冻结成功(通道交易专用) 14:通道已撤 15:通道部成部撤 16:成交失败违约(荷兰式竞拍专用)
 
+	Goodscode    string `json:"goodscode"  xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
 	Goodsname    string `json:"goodsname"  xorm:"'GOODSNAME'" binding:"required"` // 商品名称
 	Decimalplace int64  `json:"decimalplace"  xorm:"'DECIMALPLACE'"`              // 报价小数位
 
@@ -316,19 +317,18 @@ type HybsMyBuyOrderDetail struct {
 }
 
 // GetHsbyBuyMyOrderDetails 获取“我的订单”数据(包括一二级市场)
-// 输入 accountID int 资金账户
+// 输入 accountIDs string 资金账户列表
 // 输入 myBuyStatus int "我的订单"状态, 1:抢购中 2:求购中 3:已完成
 // 输出 []HybsMyBuyOrderDetail “我的订单”数据
 // 输出 error error
-func GetHsbyBuyMyOrderDetails(accountID, myBuyStatus int) ([]HybsMyBuyOrderDetail, error) {
-	engine := db.GetEngine()
-
+func GetHsbyBuyMyOrderDetails(accountIDs string, myBuyStatus int) ([]HybsMyBuyOrderDetail, error) {
 	// 获取市场信息
 	markets, err := GetMarkets()
 	if err != nil {
 		return nil, err
 	}
 
+	engine := db.GetEngine()
 	// 委托状态
 	orderStatus := "0" // 单据状态,为0的时候查询全部
 	marketID := 0      // 我的订单包括一二级市场的单据,目前暂时由服务直接报相关类型的第一个市场
@@ -358,7 +358,7 @@ func GetHsbyBuyMyOrderDetails(accountID, myBuyStatus int) ([]HybsMyBuyOrderDetai
 	hybsMyBuyOrderDetails := make([]HybsMyBuyOrderDetail, 0)
 	session := engine.Table("TRADE_ORDERDETAIL").
 		Select(`TRADE_ORDERDETAIL.*, 
-				GOODS.GOODSNAME, GOODS.DECIMALPLACE, 
+				GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, 
 				HSBY_GOODSEX.PICURLS, 
 				MARKET.TRADEMODE, 
 				ENUMDICITEM.PARAM2 CURRENCYSIGN,
@@ -368,7 +368,7 @@ func GetHsbyBuyMyOrderDetails(accountID, myBuyStatus int) ([]HybsMyBuyOrderDetai
 		Join("LEFT", "ENUMDICITEM", "GOODS.CURRENCYID = ENUMDICITEM.ENUMITEMNAME and ENUMDICITEM.ENUMDICCODE = 'currency'").
 		Join("LEFT", "MARKET", "MARKET.MARKETID = TRADE_ORDERDETAIL.MARKETID").
 		Join("LEFT", "HSBY_SUPPLIERINFO", "HSBY_SUPPLIERINFO.VENDORID = HSBY_GOODSEX.VENDORID").
-		Where("TRADE_ORDERDETAIL.ACCOUNTID = ?", accountID)
+		Where(fmt.Sprintf("TRADE_ORDERDETAIL.ACCOUNTID in (%s)", accountIDs))
 	// 是否过滤市场(抢购中、求购中)
 	if marketID > 0 {
 		session = session.And("TRADE_ORDERDETAIL.MARKETID = ?", marketID)
@@ -405,3 +405,42 @@ func GetHsbyBuyMyOrderDetails(accountID, myBuyStatus int) ([]HybsMyBuyOrderDetai
 
 	return hybsMyBuyOrderDetails, nil
 }
+
+// HsbyMyGoods 我的商品(买方向持仓)
+type HsbyMyGoods struct {
+	Accountid          int64   `json:"accountid"  xorm:"'ACCOUNTID'" binding:"required"` // 账号Id
+	Goodsid            int32   `json:"goodsid"  xorm:"'GOODSID'" binding:"required"`     // 商品Id
+	Buycurpositionqty  int64   `json:"buycurpositionqty"  xorm:"'BUYCURPOSITIONQTY'"`    // 买当前持仓总数量
+	Buycurholderamount float64 `json:"buycurholderamount"  xorm:"'BUYCURHOLDERAMOUNT'"`  // 买当前持仓总金额[商品币种]
+
+	Goodscode    string `json:"goodscode"  xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
+	Goodsname    string `json:"goodsname"  xorm:"'GOODSNAME'" binding:"required"` // 商品名称
+	Decimalplace int64  `json:"decimalplace"  xorm:"'DECIMALPLACE'"`              // 报价小数位
+
+	Picurls string `json:"picurls"  xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
+
+	Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
+}
+
+// GetHsbyMyGoods 获取“我的商品”信息
+// 输入 accountIDs string 资金账户列表,格式 1,2,3
+// 输出 []HsbyMyGoods “我的商品”信息
+// 输入 error error
+func GetHsbyMyGoods(accountIDs string) ([]HsbyMyGoods, error) {
+	engine := db.GetEngine()
+
+	hsbyMyGoodses := make([]HsbyMyGoods, 0)
+	if err := engine.Table("TRADEPOSITION").
+		Select(`TRADEPOSITION.*, 
+				GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, 
+				HSBY_GOODSEX.PICURLS, 
+				ENUMDICITEM.PARAM2 CURRENCYSIGN`).
+		Join("LEFT", "GOODS", "GOODS.GOODSID = TRADEPOSITION.GOODSID").
+		Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = GOODS.GOODSID").
+		Join("LEFT", "ENUMDICITEM", "GOODS.CURRENCYID = ENUMDICITEM.ENUMITEMNAME and ENUMDICITEM.ENUMDICCODE = 'currency'").
+		Where(fmt.Sprintf("TRADEPOSITION.ACCOUNTID in (%s)", accountIDs)).Find(&hsbyMyGoodses); err != nil {
+		return nil, err
+	}
+
+	return hsbyMyGoodses, nil
+}

+ 2 - 0
routers/router.go

@@ -170,6 +170,8 @@ func InitRouter() *gin.Engine {
 		hsbyR.GET("/QueryHsbyGoodsOrderDetails", hsby.QueryHsbyGoodsOrderDetails)
 		// 查询“我的订单”信息
 		hsbyR.GET("/QueryHsbyMyBuyOrderDetails", hsby.QueryHsbyMyBuyOrderDetails)
+		// 查询“我的商品”信息
+		hsbyR.GET("/QueryHsbyMyGoods", hsby.QueryHsbyMyGoods)
 	}
 
 	return r