Sfoglia il codice sorgente

1、增加“我的订单-已完成”接口;
2、海商4个商品接口增加“合约单位”字段返回;
3、“我的包裹”(提货单)增加手机号码解密功能。

zhou.xiaoning 5 anni fa
parent
commit
2fe77455be
6 ha cambiato i file con 567 aggiunte e 0 eliminazioni
  1. 76 0
      controllers/hsby/hsby.go
  2. 136 0
      docs/docs.go
  3. 136 0
      docs/swagger.json
  4. 98 0
      docs/swagger.yaml
  5. 119 0
      models/hsby.go
  6. 2 0
      routers/router.go

+ 76 - 0
controllers/hsby/hsby.go

@@ -668,3 +668,79 @@ func QueryProvincesAndCities(c *gin.Context) {
 	logger.GetLogger().Debugln("QueryProvincesAndCities successed: %v", rst)
 	appG.Response(http.StatusOK, e.SUCCESS, rst)
 }
+
+// QueryHsbyBuyMyTradeDetailReq 查询"我的订单 - 已完成"单据信息请求参数
+type QueryHsbyBuyMyTradeDetailReq struct {
+	app.PageInfo
+	AccountIDs string `form:"accountIDs" binding:"required"`
+}
+
+// QueryHsbyBuyMyTradeDetail 查询"我的订单 - 已完成"单据信息
+// @Summary 查询"我的订单 - 已完成"单据信息
+// @Produce json
+// @Security ApiKeyAuth
+// @Param page query int false "页码"
+// @Param pagesize query int false "每页条数"
+// @Param accountIDs query string true "资金账户列表,格式:1,2,3"
+// @Success 200 {object} models.HsbyBuyMyTradeDetail
+// @Failure 500 {object} app.Response
+// @Router /HSBY/QueryHsbyBuyMyTradeDetail [get]
+// @Tags 定制【海商报业】
+func QueryHsbyBuyMyTradeDetail(c *gin.Context) {
+	appG := app.Gin{C: c}
+
+	// 获取请求参数
+	var req QueryHsbyBuyMyTradeDetailReq
+	if err := appG.C.ShouldBindQuery(&req); err != nil {
+		logger.GetLogger().Errorf("QueryHsbyBuyMyTradeDetail failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
+		return
+	}
+
+	// 获取数据
+	var orders []models.HsbyBuyMyTradeDetail
+	var err error
+	orders, err = models.GetHsbyBuyMyTradeDetails(req.AccountIDs)
+	if err != nil {
+		// 查询失败
+		logger.GetLogger().Errorf("QueryHsbyBuyMyTradeDetail failed: %s", err.Error())
+		appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
+		return
+	}
+
+	// 排序
+	sort.Slice(orders, func(i int, j int) bool {
+		return orders[i].Time.After(orders[j].Time)
+	})
+
+	// 分页
+	total := len(orders)
+	if req.PageSize > 0 {
+		rstByPage := make([]models.HsbyBuyMyTradeDetail, 0)
+		// 开始上标
+		start := req.Page * req.PageSize
+		// 结束下标
+		end := start + req.PageSize
+
+		if start <= len(orders) {
+			// 判断结束下标是否越界
+			if end > len(orders) {
+				end = len(orders)
+			}
+			rstByPage = orders[start:end]
+		} else {
+			rstByPage = orders[0:0]
+		}
+
+		orders = rstByPage
+	}
+
+	// 查询成功返回
+	if req.PageSize > 0 {
+		logger.GetLogger().Debugln("QueryHsbyBuyMyTradeDetail successed: %v", orders)
+		appG.ResponseByPage(http.StatusOK, e.SUCCESS, orders, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: total})
+	} else {
+		logger.GetLogger().Debugln("QueryHsbyBuyMyTradeDetail successed: %v", orders)
+		appG.Response(http.StatusOK, e.SUCCESS, orders)
+	}
+}

+ 136 - 0
docs/docs.go

@@ -789,6 +789,57 @@ var doc = `{
                 }
             }
         },
+        "/HSBY/QueryHsbyBuyMyTradeDetail": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "定制【海商报业】"
+                ],
+                "summary": "查询\"我的订单 - 已完成\"单据信息",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "页码",
+                        "name": "page",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "每页条数",
+                        "name": "pagesize",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "资金账户列表,格式:1,2,3",
+                        "name": "accountIDs",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/models.HsbyBuyMyTradeDetail"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/HSBY/QueryHsbyGoodsOrderDetails": {
             "get": {
                 "security": [
@@ -4281,6 +4332,91 @@ var doc = `{
                 }
             }
         },
+        "models.HsbyBuyMyTradeDetail": {
+            "type": "object",
+            "required": [
+                "accountid",
+                "buyorsell",
+                "goodscode",
+                "goodsid",
+                "goodsname",
+                "marketid",
+                "orderid",
+                "qty",
+                "time",
+                "trademode"
+            ],
+            "properties": {
+                "accountid": {
+                    "description": "账户ID[报价币种]",
+                    "type": "integer"
+                },
+                "agreeunit": {
+                    "description": "合约单位",
+                    "type": "number"
+                },
+                "amount": {
+                    "description": "金额 = 价格 * 数量 * 合约单位",
+                    "type": "number"
+                },
+                "buyorsell": {
+                    "description": "买卖 - 0:买 1:卖",
+                    "type": "integer"
+                },
+                "currencysign": {
+                    "description": "货币符号",
+                    "type": "string"
+                },
+                "decimalplace": {
+                    "description": "报价小数位",
+                    "type": "integer"
+                },
+                "goodscode": {
+                    "description": "商品代码(内部)",
+                    "type": "string"
+                },
+                "goodsid": {
+                    "description": "商品ID",
+                    "type": "integer"
+                },
+                "goodsname": {
+                    "description": "商品名称",
+                    "type": "string"
+                },
+                "marketid": {
+                    "description": "市场ID",
+                    "type": "integer"
+                },
+                "orderid": {
+                    "description": "单号(成交单号)",
+                    "type": "string"
+                },
+                "picurls": {
+                    "description": "介绍图片[多张用逗号分隔]",
+                    "type": "string"
+                },
+                "price": {
+                    "description": "价格",
+                    "type": "number"
+                },
+                "qty": {
+                    "description": "数量",
+                    "type": "integer"
+                },
+                "time": {
+                    "description": "时间",
+                    "type": "string"
+                },
+                "trademode": {
+                    "description": "交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价",
+                    "type": "integer"
+                },
+                "vendorname": {
+                    "description": "供应商名称",
+                    "type": "string"
+                }
+            }
+        },
         "models.HsbyGoodsOrderDetail": {
             "type": "object",
             "required": [

+ 136 - 0
docs/swagger.json

@@ -773,6 +773,57 @@
                 }
             }
         },
+        "/HSBY/QueryHsbyBuyMyTradeDetail": {
+            "get": {
+                "security": [
+                    {
+                        "ApiKeyAuth": []
+                    }
+                ],
+                "produces": [
+                    "application/json"
+                ],
+                "tags": [
+                    "定制【海商报业】"
+                ],
+                "summary": "查询\"我的订单 - 已完成\"单据信息",
+                "parameters": [
+                    {
+                        "type": "integer",
+                        "description": "页码",
+                        "name": "page",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "每页条数",
+                        "name": "pagesize",
+                        "in": "query"
+                    },
+                    {
+                        "type": "string",
+                        "description": "资金账户列表,格式:1,2,3",
+                        "name": "accountIDs",
+                        "in": "query",
+                        "required": true
+                    }
+                ],
+                "responses": {
+                    "200": {
+                        "description": "OK",
+                        "schema": {
+                            "$ref": "#/definitions/models.HsbyBuyMyTradeDetail"
+                        }
+                    },
+                    "500": {
+                        "description": "Internal Server Error",
+                        "schema": {
+                            "$ref": "#/definitions/app.Response"
+                        }
+                    }
+                }
+            }
+        },
         "/HSBY/QueryHsbyGoodsOrderDetails": {
             "get": {
                 "security": [
@@ -4265,6 +4316,91 @@
                 }
             }
         },
+        "models.HsbyBuyMyTradeDetail": {
+            "type": "object",
+            "required": [
+                "accountid",
+                "buyorsell",
+                "goodscode",
+                "goodsid",
+                "goodsname",
+                "marketid",
+                "orderid",
+                "qty",
+                "time",
+                "trademode"
+            ],
+            "properties": {
+                "accountid": {
+                    "description": "账户ID[报价币种]",
+                    "type": "integer"
+                },
+                "agreeunit": {
+                    "description": "合约单位",
+                    "type": "number"
+                },
+                "amount": {
+                    "description": "金额 = 价格 * 数量 * 合约单位",
+                    "type": "number"
+                },
+                "buyorsell": {
+                    "description": "买卖 - 0:买 1:卖",
+                    "type": "integer"
+                },
+                "currencysign": {
+                    "description": "货币符号",
+                    "type": "string"
+                },
+                "decimalplace": {
+                    "description": "报价小数位",
+                    "type": "integer"
+                },
+                "goodscode": {
+                    "description": "商品代码(内部)",
+                    "type": "string"
+                },
+                "goodsid": {
+                    "description": "商品ID",
+                    "type": "integer"
+                },
+                "goodsname": {
+                    "description": "商品名称",
+                    "type": "string"
+                },
+                "marketid": {
+                    "description": "市场ID",
+                    "type": "integer"
+                },
+                "orderid": {
+                    "description": "单号(成交单号)",
+                    "type": "string"
+                },
+                "picurls": {
+                    "description": "介绍图片[多张用逗号分隔]",
+                    "type": "string"
+                },
+                "price": {
+                    "description": "价格",
+                    "type": "number"
+                },
+                "qty": {
+                    "description": "数量",
+                    "type": "integer"
+                },
+                "time": {
+                    "description": "时间",
+                    "type": "string"
+                },
+                "trademode": {
+                    "description": "交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价",
+                    "type": "integer"
+                },
+                "vendorname": {
+                    "description": "供应商名称",
+                    "type": "string"
+                }
+            }
+        },
         "models.HsbyGoodsOrderDetail": {
             "type": "object",
             "required": [

+ 98 - 0
docs/swagger.yaml

@@ -1250,6 +1250,72 @@ definitions:
     - autoid
     - divisioncode
     type: object
+  models.HsbyBuyMyTradeDetail:
+    properties:
+      accountid:
+        description: 账户ID[报价币种]
+        type: integer
+      agreeunit:
+        description: 合约单位
+        type: number
+      amount:
+        description: 金额 = 价格 * 数量 * 合约单位
+        type: number
+      buyorsell:
+        description: 买卖 - 0:买 1:卖
+        type: integer
+      currencysign:
+        description: 货币符号
+        type: string
+      decimalplace:
+        description: 报价小数位
+        type: integer
+      goodscode:
+        description: 商品代码(内部)
+        type: string
+      goodsid:
+        description: 商品ID
+        type: integer
+      goodsname:
+        description: 商品名称
+        type: string
+      marketid:
+        description: 市场ID
+        type: integer
+      orderid:
+        description: 单号(成交单号)
+        type: string
+      picurls:
+        description: 介绍图片[多张用逗号分隔]
+        type: string
+      price:
+        description: 价格
+        type: number
+      qty:
+        description: 数量
+        type: integer
+      time:
+        description: 时间
+        type: string
+      trademode:
+        description: 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式
+          21:竞拍-大宗式 22:受托竞价
+        type: integer
+      vendorname:
+        description: 供应商名称
+        type: string
+    required:
+    - accountid
+    - buyorsell
+    - goodscode
+    - goodsid
+    - goodsname
+    - marketid
+    - orderid
+    - qty
+    - time
+    - trademode
+    type: object
   models.HsbyGoodsOrderDetail:
     properties:
       buyorsell:
@@ -4133,6 +4199,38 @@ paths:
       summary: 查询现货合同表信息(指定策略ID、未结束的)
       tags:
       - 风险管理
+  /HSBY/QueryHsbyBuyMyTradeDetail:
+    get:
+      parameters:
+      - description: 页码
+        in: query
+        name: page
+        type: integer
+      - description: 每页条数
+        in: query
+        name: pagesize
+        type: integer
+      - description: 资金账户列表,格式:1,2,3
+        in: query
+        name: accountIDs
+        required: true
+        type: string
+      produces:
+      - application/json
+      responses:
+        "200":
+          description: OK
+          schema:
+            $ref: '#/definitions/models.HsbyBuyMyTradeDetail'
+        "500":
+          description: Internal Server Error
+          schema:
+            $ref: '#/definitions/app.Response'
+      security:
+      - ApiKeyAuth: []
+      summary: 查询"我的订单 - 已完成"单据信息
+      tags:
+      - 定制【海商报业】
   /HSBY/QueryHsbyGoodsOrderDetails:
     get:
       description: 说明:查询结果已按委托价格和委托时间排序

+ 119 - 0
models/hsby.go

@@ -1,6 +1,7 @@
 package models
 
 import (
+	"encoding/hex"
 	"fmt"
 	"math"
 	"mtp2_if/db"
@@ -906,6 +907,19 @@ func GetHsbyMyPackages(accountIDs string, takeOrderStatus int) ([]HsbyMyPackage,
 		return nil, err
 	}
 
+	// FIXME:- 目前暂时在服务端对手机号码进行解密
+	key, _ := hex.DecodeString(utils.AESSecretKey)
+	for i := range myPackages {
+		myPackage := &myPackages[i]
+
+		// 解密手机号码
+		if phonenum, err := hex.DecodeString(myPackage.Phonenum); err == nil { // hex -> []byte
+			if mobile, err := utils.AESDecrypt(phonenum, key); err == nil {
+				myPackage.Phonenum = string(mobile)
+			}
+		}
+	}
+
 	return myPackages, nil
 }
 
@@ -938,3 +952,108 @@ func GetHsbyProvincesAndCities(provinceID int) ([]Division, error) {
 
 	return divisions, nil
 }
+
+// HsbyBuyMyTradeDetail "我的订单 - 已完成"单据信息(一二级市场成交单,包括历史数据)
+type HsbyBuyMyTradeDetail struct {
+	Orderid   string    `json:"orderid"  xorm:"'ORDERID'" binding:"required"`     // 单号(成交单号)
+	Marketid  int32     `json:"marketid"  xorm:"'MARKETID'" binding:"required"`   // 市场ID
+	Goodsid   int32     `json:"goodsid"  xorm:"'GOODSID'" binding:"required"`     // 商品ID
+	Accountid int64     `json:"accountid"  xorm:"'ACCOUNTID'" binding:"required"` // 账户ID[报价币种]
+	Buyorsell int32     `json:"buyorsell"  xorm:"'BUYORSELL'" binding:"required"` // 买卖 - 0:买 1:卖
+	Price     float64   `json:"price"  xorm:"'PRICE'"`                            // 价格
+	Qty       int64     `json:"qty"  xorm:"'QTY'" binding:"required"`             // 数量
+	Time      time.Time `json:"time"  xorm:"'TIME'" binding:"required"`           // 时间
+	Amount    float64   `json:"amount" xorm:"'AMOUNT'"`                           // 金额 = 价格 * 数量 * 合约单位
+
+	Goodscode    string  `json:"goodscode"  xorm:"'GOODSCODE'" binding:"required"` // 商品代码(内部)
+	Goodsname    string  `json:"goodsname"  xorm:"'GOODSNAME'" binding:"required"` // 商品名称
+	Decimalplace int64   `json:"decimalplace"  xorm:"'DECIMALPLACE'"`              // 报价小数位
+	Agreeunit    float64 `json:"agreeunit"  xorm:"'AGREEUNIT'"`                    // 合约单位
+
+	Picurls string `json:"picurls"  xorm:"'PICURLS'"` // 介绍图片[多张用逗号分隔]
+
+	Trademode uint32 `json:"trademode"  xorm:"'TRADEMODE'" binding:"required"` // 交易模式 - 10:做市 13:竞价 15:通道交易 16:挂牌点选 17:仓单贸易 18:期权 19:竞拍-降价式 20:竞拍-竞价式 21:竞拍-大宗式 22:受托竞价
+
+	Currencysign string `json:"currencysign" xorm:"'CURRENCYSIGN'"` // 货币符号
+
+	Vendorname string `json:"vendorname"  xorm:"'VENDORNAME'"` // 供应商名称
+}
+
+// GetHsbyBuyMyTradeDetails 获取"我的订单 - 已完成"单据信息(一二级市场成交单,包括历史数据)
+// 输入 accountIDs string 资金账户列表
+// 输出 []HsbyBuyMyTradeDetail "我的订单 - 已完成"单据信息
+// 输出 error error
+func GetHsbyBuyMyTradeDetails(accountIDs string) ([]HsbyBuyMyTradeDetail, error) {
+	// 获取市场信息
+	markets, err := GetMarkets()
+	if err != nil {
+		return nil, err
+	}
+
+	engine := db.GetEngine()
+	marketIDs := "" // 我的订单包括一二级市场卖方向成交单(包括历史成交单)
+	// 默认取 TradeMode = 16
+	for _, v := range markets {
+		if v.Trademode == 16 || v.Trademode == 71 {
+			if len(marketIDs) == 0 {
+				marketIDs = strconv.Itoa(int(v.Marketid))
+			} else {
+				marketIDs += "," + strconv.Itoa(int(v.Marketid))
+			}
+		}
+	}
+
+	orders := make([]HsbyBuyMyTradeDetail, 0)
+
+	// 当前成交单
+	curOrders := make([]HsbyBuyMyTradeDetail, 0)
+	if err := engine.Table("TRADE_TRADEDETAIL").
+		Select(`to_char(TRADE_TRADEDETAIL.TRADEID) ORDERID, 
+				TRADE_TRADEDETAIL.MARKETID, TRADE_TRADEDETAIL.GOODSID, TRADE_TRADEDETAIL.ACCOUNTID, TRADE_TRADEDETAIL.BUYORSELL,
+				TRADE_TRADEDETAIL.TRADEPRICE PRICE, TRADE_TRADEDETAIL.TRADEQTY QTY, TRADE_TRADEDETAIL.TRADETIME TIME, TRADE_TRADEDETAIL.TRADEAMOUNT AMOUNT, 
+				GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, GOODS.AGREEUNIT, 
+				HSBY_GOODSEX.PICURLS, 
+				MARKET.TRADEMODE, 
+				ENUMDICITEM.PARAM2 CURRENCYSIGN, 
+				HSBY_SUPPLIERINFO.VENDORNAME`).
+		Join("LEFT", "GOODS", "GOODS.GOODSID = TRADE_TRADEDETAIL.GOODSID").
+		Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = GOODS.GOODSID").
+		Join("LEFT", "ENUMDICITEM", "GOODS.CURRENCYID = ENUMDICITEM.ENUMITEMNAME and ENUMDICITEM.ENUMDICCODE = 'currency'").
+		Join("LEFT", "MARKET", "MARKET.MARKETID = TRADE_TRADEDETAIL.MARKETID").
+		Join("LEFT", "HSBY_SUPPLIERINFO", "HSBY_SUPPLIERINFO.VENDORID = HSBY_GOODSEX.VENDORID").
+		Where(fmt.Sprintf(`TRADE_TRADEDETAIL.BUYORSELL = 0 
+						   and TRADE_TRADEDETAIL.ACCOUNTID in (%s)`, accountIDs)).
+		And(fmt.Sprintf("TRADE_TRADEDETAIL.MARKETID in (%s)", marketIDs)).Find(&curOrders); err != nil {
+		return nil, err
+	}
+	if len(curOrders) > 0 {
+		orders = append(orders, curOrders...)
+	}
+
+	// 历史成交单
+	hisOrders := make([]HsbyBuyMyTradeDetail, 0)
+	if err := engine.Table("HIS_TRADE_TRADEDETAIL").
+		Select(`to_char(HIS_TRADE_TRADEDETAIL.TRADEID) ORDERID, 
+				HIS_TRADE_TRADEDETAIL.MARKETID, HIS_TRADE_TRADEDETAIL.GOODSID, HIS_TRADE_TRADEDETAIL.ACCOUNTID, HIS_TRADE_TRADEDETAIL.BUYORSELL,
+				HIS_TRADE_TRADEDETAIL.TRADEPRICE PRICE, HIS_TRADE_TRADEDETAIL.TRADEQTY QTY, HIS_TRADE_TRADEDETAIL.TRADETIME TIME, HIS_TRADE_TRADEDETAIL.TRADEAMOUNT AMOUNT, 
+				GOODS.GOODSCODE, GOODS.GOODSNAME, GOODS.DECIMALPLACE, GOODS.AGREEUNIT, 
+				HSBY_GOODSEX.PICURLS, 
+				MARKET.TRADEMODE, 
+				ENUMDICITEM.PARAM2 CURRENCYSIGN, 
+				HSBY_SUPPLIERINFO.VENDORNAME`).
+		Join("LEFT", "GOODS", "GOODS.GOODSID = HIS_TRADE_TRADEDETAIL.GOODSID").
+		Join("LEFT", "HSBY_GOODSEX", "HSBY_GOODSEX.GOODSID = GOODS.GOODSID").
+		Join("LEFT", "ENUMDICITEM", "GOODS.CURRENCYID = ENUMDICITEM.ENUMITEMNAME and ENUMDICITEM.ENUMDICCODE = 'currency'").
+		Join("LEFT", "MARKET", "MARKET.MARKETID = HIS_TRADE_TRADEDETAIL.MARKETID").
+		Join("LEFT", "HSBY_SUPPLIERINFO", "HSBY_SUPPLIERINFO.VENDORID = HSBY_GOODSEX.VENDORID").
+		Where(fmt.Sprintf(`HIS_TRADE_TRADEDETAIL.BUYORSELL = 0 and HIS_TRADE_TRADEDETAIL.ISVALIDDATA = 1 
+						   and HIS_TRADE_TRADEDETAIL.ACCOUNTID in (%s)`, accountIDs)).
+		And(fmt.Sprintf("HIS_TRADE_TRADEDETAIL.MARKETID in (%s)", marketIDs)).Find(&hisOrders); err != nil {
+		return nil, err
+	}
+	if len(hisOrders) > 0 {
+		orders = append(orders, hisOrders...)
+	}
+
+	return orders, nil
+}

+ 2 - 0
routers/router.go

@@ -213,6 +213,8 @@ func InitRouter() *gin.Engine {
 		hsbyR.POST("/SetHsbyMyPackagesStatus", hsby.SetHsbyMyPackagesStatus)
 		// 查询省市信息(不包括区)
 		hsbyR.GET("/QueryProvincesAndCities", hsby.QueryProvincesAndCities)
+		// 查询"我的订单 - 已完成"单据信息
+		hsbyR.GET("/QueryHsbyBuyMyTradeDetail", hsby.QueryHsbyBuyMyTradeDetail)
 	}
 
 	return r