-
Notifications
You must be signed in to change notification settings - Fork 0
/
bitmapservsinglelogic.go
78 lines (71 loc) · 1.97 KB
/
bitmapservsinglelogic.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
78
package logic
import (
"context"
"fmt"
"github.com/tal-tech/go-zero/core/stores/sqlx"
"github.com/weblfe/bitmap_service/api/internal/svc"
"github.com/weblfe/bitmap_service/api/internal/types"
"github.com/weblfe/bitmap_service/api/model"
"github.com/tal-tech/go-zero/core/logx"
)
type BitMapServSingleLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
func NewBitMapServSingleLogic(ctx context.Context, svcCtx *svc.ServiceContext) BitMapServSingleLogic {
return BitMapServSingleLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *BitMapServSingleLogic) BitMapServSingle(req types.SingleRequest) (*types.SingleResponse, error) {
if req.DataSource != "" {
l.svcCtx.Model = model.NewUserDayLoginModel(sqlx.NewMysql(l.svcCtx.Config.DataSource), req.DataSource, l.svcCtx.Config.Cache, l.svcCtx.Config)
}
var (
total = 0
left = 0
keep float32 = 0.00
name = getName(req.Date, int64(req.Day), req.Channel)
)
userArr, err := l.svcCtx.Model.GetUserBitMapArr(model.QueryMap{Day: req.Day, Channel: req.Channel, Role: req.Role, Date: req.Date, Type: model.ParserDateType(req.Type)})
if err != nil {
return &types.SingleResponse{
BaseResponse: types.BaseResponse{
Code: 200,
Msg: err.Error(),
ErrorNo: 500,
},
Data: nil,
}, nil
}
if len(userArr) == 0 {
return &types.SingleResponse{
BaseResponse: types.BaseResponse{
Code: 200,
Msg: "OK",
},
Data: &types.KeeperStruct{
Keep: fmt.Sprintf("%.2f", keep),
Name: fmt.Sprintf("%s: %.2f%s", name, keep, "%"),
Register: total,
Left: left,
},
}, nil
}
keep, total, left = GetUserDayKeepByBitmapArr(userArr)
return &types.SingleResponse{
BaseResponse: types.BaseResponse{
Code: 200,
Msg: "OK",
},
Data: &types.KeeperStruct{
Keep: fmt.Sprintf("%.2f", keep),
Name: fmt.Sprintf("%s: %.2f%s", name, keep, "%"),
Register: total,
Left: left,
},
}, nil
}