query_set_statistics.go
3.0 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package service
import (
"github.com/linmadan/egglib-go/core/application"
"github.com/linmadan/egglib-go/utils/xtime"
"github.com/zeromicro/go-zero/core/fx"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/factory"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/application/querySet/query"
"gitlab.fjmaimaimai.com/allied-creation/character-library-metadata-bastion/pkg/domain"
)
func (querySetService *QuerySetService) StatisticsQuery(ctx *domain.Context, query *query.StatisticsQuery) (interface{}, error) {
if err := query.ValidateQuery(); err != nil {
return nil, application.ThrowError(application.ARG_ERROR, err.Error())
}
transactionContext, err := factory.CreateTransactionContext(nil)
if err != nil {
return nil, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
querySetRepository, _, _ := factory.FastPgQuerySet(transactionContext, 0)
var (
total int64
totalToday int64
totalYesterday int64
totalEnable int64
platformTotal int64
platformTotalYesterday int64
)
fx.Parallel(func() {
total, _, err = querySetRepository.Find(map[string]interface{}{
"context": ctx,
"limit": 1,
"type": domain.SchemaTable.ToString(),
})
if err != nil {
return
}
totalEnable, _, err = querySetRepository.Find(map[string]interface{}{
"context": ctx,
"limit": 1,
"type": domain.SchemaTable.ToString(),
"status": domain.StatusOn,
})
if err != nil {
return
}
totalToday, _, err = querySetRepository.Find(map[string]interface{}{
"context": ctx,
"limit": 1,
"type": domain.SchemaTable.ToString(),
"beginTime": xtime.BeginningOfDay().Local(),
"endTime": xtime.BeginningOfDay().AddDate(0, 0, 1).Local(),
})
if err != nil {
return
}
totalYesterday, _, err = querySetRepository.Find(map[string]interface{}{
"context": ctx,
"limit": 1,
"type": domain.SchemaTable.ToString(),
"beginTime": xtime.BeginningOfDay().AddDate(0, 0, -1).Local(),
"endTime": xtime.BeginningOfDay().Local(),
})
if err != nil {
return
}
}, func() {
platformTotal, _, err = querySetRepository.Find(map[string]interface{}{
"limit": 1,
"type": domain.SchemaTable.ToString(),
})
if err != nil {
return
}
platformTotalYesterday, _, err = querySetRepository.Find(map[string]interface{}{
"limit": 1,
"type": domain.SchemaTable.ToString(),
"beginTime": xtime.BeginningOfDay().AddDate(0, 0, -1).Local(),
"endTime": xtime.BeginningOfDay().Local(),
})
if err != nil {
return
}
})
if err != nil {
return nil, factory.FastError(err)
}
return map[string]interface{}{
"schemaStatistics": map[string]interface{}{
"total": total,
"totalToday": totalToday,
"totalYesterday": totalYesterday,
"totalEnable": totalEnable,
},
"platformSchemaStatistics": map[string]interface{}{
"total": platformTotal,
"totalYesterday": platformTotalYesterday,
},
}, nil
}