-
Notifications
You must be signed in to change notification settings - Fork 31
/
get_order_list_logic.go
77 lines (69 loc) · 2.64 KB
/
get_order_list_logic.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package logic
import (
"context"
"github.com/luxun9527/gex/app/order/rpc/internal/svc"
"github.com/luxun9527/gex/app/order/rpc/pb"
"github.com/luxun9527/gex/common/errs"
enum "github.com/luxun9527/gex/common/proto/enum"
"github.com/luxun9527/gex/common/utils"
logger "github.com/luxun9527/zaplog"
"github.com/zeromicro/go-zero/core/logx"
)
type GetOrderListLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewGetOrderListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetOrderListLogic {
return &GetOrderListLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// GetOrderList 获取用户订单列表
func (l *GetOrderListLogic) GetOrderList(in *pb.GetOrderListByUserReq) (*pb.GetOrderListByUserResp, error) {
entrustOrder := l.svcCtx.Query.EntrustOrder
statusCond := make([]int32, 0, len(in.StatusList))
for _, v := range in.StatusList {
statusCond = append(statusCond, int32(v))
}
result, err := entrustOrder.WithContext(l.ctx).
Omit(entrustOrder.UpdatedAt).
Where(entrustOrder.UserID.Eq(in.UserId), entrustOrder.ID.Gt(in.Id)).
Where(entrustOrder.Status.In(statusCond...)).
Limit(int(in.PageSize)).
Order(entrustOrder.ID.Desc()).
Find()
count, err := entrustOrder.WithContext(l.ctx).Where(entrustOrder.UserID.Eq(in.UserId), entrustOrder.ID.Gt(in.Id)).
Where(entrustOrder.Status.In(statusCond...)).Count()
if err != nil {
return nil, errs.ExecSqlFailed
}
if err != nil {
logx.Errorw("GetOrderList query user order list failed", logger.ErrorField(err))
return nil, errs.ExecSqlFailed
}
orders := make([]*pb.Order, 0, len(result))
for _, v := range result {
order := &pb.Order{
Id: v.ID,
OrderId: v.OrderID,
UserId: v.UserID,
SymbolId: v.SymbolID,
SymbolName: v.SymbolName,
Qty: utils.PrecCut(v.Qty, l.svcCtx.Config.SymbolInfo.BaseCoinPrec.Load()),
Price: utils.PrecCut(v.Price, l.svcCtx.Config.SymbolInfo.QuoteCoinPrec.Load()),
Amount: utils.PrecCut(v.Amount, l.svcCtx.Config.SymbolInfo.QuoteCoinPrec.Load()),
Side: enum.Side(v.Side),
Status: enum.OrderStatus(v.Status),
OrderType: enum.OrderType(v.OrderType),
FilledQty: utils.PrecCut(v.FilledQty, l.svcCtx.Config.SymbolInfo.BaseCoinPrec.Load()),
FilledAmount: utils.PrecCut(v.FilledAmount, l.svcCtx.Config.SymbolInfo.QuoteCoinPrec.Load()),
FilledAvgPrice: utils.PrecCut(v.FilledAvgPrice, l.svcCtx.Config.SymbolInfo.QuoteCoinPrec.Load()),
CreatedAt: v.CreatedAt,
}
orders = append(orders, order)
}
return &pb.GetOrderListByUserResp{OrderList: orders, Total: count}, nil
}