Pārlūkot izejas kodu

/Order/QueryHisTradeOrderDetail
/Order/QueryHisTradeDetail
接口增加分页功能

zhou.xiaoning 2 gadi atpakaļ
vecāks
revīzija
ada817a5e8

+ 4 - 4
controllers/guangzuan/tradeService.go

@@ -18,8 +18,8 @@ import (
 // @Security Group
 // @Param    userid   query    int    true  "用户ID"
 // @Param    executestatus query    int false "执行状态 - 1:未生效 2:进行中 3:已结束"
-// @Param    page          query    int false "页码"
-// @Param    pagesize      query    int false "每页条数"
+// @Param    page     query    int    false "页码"
+// @Param    pagesize query    int    false "每页条数"
 // @Success  200           {array}  models.GzcjjcorderM
 // @Failure  500     {object} app.Response
 // @Router   /Guangzuan/QueryGZCJJCOrder [get]
@@ -39,8 +39,8 @@ func QueryGZCJJCOrder(c *gin.Context) {
 // @Security Group
 // @Param    userid        query    int true  "用户ID"
 // @Param    orderid  query    string false "单据ID"
-// @Param    page     query    int    false "页码"
-// @Param    pagesize query    int    false "每页条数"
+// @Param    page          query    int false "页码"
+// @Param    pagesize      query    int false "每页条数"
 // @Success  200      {array}  models.GzcjjcorderdetailM
 // @Failure  500           {object} app.Response
 // @Router   /Guangzuan/QueryGZCJJCOrderDetail [get]

+ 82 - 2
controllers/order/order.go

@@ -435,6 +435,8 @@ func QueryTradeOrderDetail(c *gin.Context) {
 
 // QueryHisTradeOrderDetailReq 历史委托单查询请求参数(合约市场)
 type QueryHisTradeOrderDetailReq struct {
+	app.PageInfo
+
 	AccountID   string `form:"accountID" binding:"required"` // 资金账户 - 格式:1,2,3
 	OrderStatus string `form:"orderStatus"`                  // 委托状态 - 格式:1,2,3
 	TradeMode   string `form:"tradeMode"`                    // 交易模式 - 格式:1,2,3
@@ -481,6 +483,9 @@ func (r *QueryHisTradeOrderDetailRsp) calc() {
 // @Param    orderID     query    int    false "委托单号"
 // @Param    startDate   query    string false "开始时间 - 闭区间,格式:yyyy-MM-dd"
 // @Param    endDate     query    string false "结束时间 - 闭区间,格式:yyyy-MM-dd"
+// @Param    page      query    int    false "页码"
+// @Param    pagesize  query    int    false "每页条数"
+// @Param    pageflag  query    int    false "分页标志 0-page从0开始 1-page从1开始"
 // @Success  200         {object} QueryHisTradeOrderDetailRsp
 // @Failure  500         {object} app.Response
 // @Router   /Order/QueryHisTradeOrderDetail [get]
@@ -534,7 +539,42 @@ func QueryHisTradeOrderDetail(c *gin.Context) {
 	for i := range datas {
 		datas[i].calc()
 	}
-	appG.Response(http.StatusOK, e.SUCCESS, datas)
+	// appG.Response(http.StatusOK, e.SUCCESS, datas)
+
+	// 查询成功返回
+	if req.PageSize > 0 {
+		// 分页
+		var rst []QueryHisTradeOrderDetailRsp
+		// 开始上标
+		// 终端分页1开始
+		p := req.Page
+		if req.PageFlag != 0 {
+			p -= 1
+			if p < 0 {
+				p = 0
+			}
+		}
+		start := p * req.PageSize
+		// 结束下标
+		end := start + req.PageSize
+
+		if start <= len(datas) {
+			// 判断结束下标是否越界
+			if end > len(datas) {
+				end = len(datas)
+			}
+			rst = datas[start:end]
+		} else {
+			rst = datas[0:0]
+		}
+
+		logger.GetLogger().Debugln("QueryHisTradeOrderDetail successed: %v", rst)
+		appG.ResponseByPage(http.StatusOK, e.SUCCESS, rst, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: len(datas)})
+	} else {
+		// 不分页
+		logger.GetLogger().Debugln("QueryHisTradeOrderDetail successed: %v", datas)
+		appG.Response(http.StatusOK, e.SUCCESS, datas)
+	}
 }
 
 // QueryTradeDetailReq 成交单查询请求参数
@@ -658,6 +698,8 @@ func QueryTradeDetail(c *gin.Context) {
 
 // QueryHisTradeDetailReq 历史成交单查询请求参数
 type QueryHisTradeDetailReq struct {
+	app.PageInfo
+
 	AccountID string `form:"accountID" binding:"required"`
 	TradeID   int    `form:"tradeID"`
 	OrderID   int    `form:"orderID"`
@@ -713,6 +755,9 @@ func (r *QueryHisTradeDetailRsp) calc() {
 // @Param    tradeType query    string false "成交类别 - 格式:1,2,3"
 // @Param    startDate query    string false "开始时间 - 闭区间,格式:yyyy-MM-dd"
 // @Param    endDate   query    string false "结束时间 - 闭区间,格式:yyyy-MM-dd"
+// @Param    page        query    int    false "页码"
+// @Param    pagesize    query    int    false "每页条数"
+// @Param    pageflag    query    int    false "分页标志 0-page从0开始 1-page从1开始"
 // @Success  200       {object} QueryHisTradeDetailRsp
 // @Failure  500       {object} app.Response
 // @Router   /Order/QueryHisTradeDetail [get]
@@ -778,5 +823,40 @@ func QueryHisTradeDetail(c *gin.Context) {
 	for i := range datas {
 		datas[i].calc()
 	}
-	appG.Response(http.StatusOK, e.SUCCESS, datas)
+	// appG.Response(http.StatusOK, e.SUCCESS, datas)
+
+	// 查询成功返回
+	if req.PageSize > 0 {
+		// 分页
+		var rst []QueryHisTradeDetailRsp
+		// 开始上标
+		// 终端分页1开始
+		p := req.Page
+		if req.PageFlag != 0 {
+			p -= 1
+			if p < 0 {
+				p = 0
+			}
+		}
+		start := p * req.PageSize
+		// 结束下标
+		end := start + req.PageSize
+
+		if start <= len(datas) {
+			// 判断结束下标是否越界
+			if end > len(datas) {
+				end = len(datas)
+			}
+			rst = datas[start:end]
+		} else {
+			rst = datas[0:0]
+		}
+
+		logger.GetLogger().Debugln("QueryHisTradeDetail successed: %v", rst)
+		appG.ResponseByPage(http.StatusOK, e.SUCCESS, rst, app.PageInfo{Page: req.Page, PageSize: req.PageSize, Total: len(datas)})
+	} else {
+		// 不分页
+		logger.GetLogger().Debugln("QueryHisTradeDetail successed: %v", datas)
+		appG.Response(http.StatusOK, e.SUCCESS, datas)
+	}
 }

+ 36 - 0
docs/docs.go

@@ -13858,6 +13858,24 @@ const docTemplate = `{
                         "description": "结束时间 - 闭区间,格式:yyyy-MM-dd",
                         "name": "endDate",
                         "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "页码",
+                        "name": "page",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "每页条数",
+                        "name": "pagesize",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "分页标志 0-page从0开始 1-page从1开始",
+                        "name": "pageflag",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -13927,6 +13945,24 @@ const docTemplate = `{
                         "description": "结束时间 - 闭区间,格式:yyyy-MM-dd",
                         "name": "endDate",
                         "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "页码",
+                        "name": "page",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "每页条数",
+                        "name": "pagesize",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "分页标志 0-page从0开始 1-page从1开始",
+                        "name": "pageflag",
+                        "in": "query"
                     }
                 ],
                 "responses": {

+ 36 - 0
docs/swagger.json

@@ -13849,6 +13849,24 @@
                         "description": "结束时间 - 闭区间,格式:yyyy-MM-dd",
                         "name": "endDate",
                         "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "页码",
+                        "name": "page",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "每页条数",
+                        "name": "pagesize",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "分页标志 0-page从0开始 1-page从1开始",
+                        "name": "pageflag",
+                        "in": "query"
                     }
                 ],
                 "responses": {
@@ -13918,6 +13936,24 @@
                         "description": "结束时间 - 闭区间,格式:yyyy-MM-dd",
                         "name": "endDate",
                         "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "页码",
+                        "name": "page",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "每页条数",
+                        "name": "pagesize",
+                        "in": "query"
+                    },
+                    {
+                        "type": "integer",
+                        "description": "分页标志 0-page从0开始 1-page从1开始",
+                        "name": "pageflag",
+                        "in": "query"
                     }
                 ],
                 "responses": {

+ 24 - 0
docs/swagger.yaml

@@ -37903,6 +37903,18 @@ paths:
         in: query
         name: endDate
         type: string
+      - description: 页码
+        in: query
+        name: page
+        type: integer
+      - description: 每页条数
+        in: query
+        name: pagesize
+        type: integer
+      - description: 分页标志 0-page从0开始 1-page从1开始
+        in: query
+        name: pageflag
+        type: integer
       produces:
       - application/json
       responses:
@@ -37947,6 +37959,18 @@ paths:
         in: query
         name: endDate
         type: string
+      - description: 页码
+        in: query
+        name: page
+        type: integer
+      - description: 每页条数
+        in: query
+        name: pagesize
+        type: integer
+      - description: 分页标志 0-page从0开始 1-page从1开始
+        in: query
+        name: pageflag
+        type: integer
       produces:
       - application/json
       responses: