-
Notifications
You must be signed in to change notification settings - Fork 66
/
summary.go
184 lines (162 loc) · 5.67 KB
/
summary.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package handler
import (
"github.com/aaronchen2k/deeptest/internal/pkg/config"
"github.com/aaronchen2k/deeptest/internal/server/modules/service"
_domain "github.com/aaronchen2k/deeptest/pkg/domain"
logUtils "github.com/aaronchen2k/deeptest/pkg/lib/log"
"github.com/aaronchen2k/deeptest/saas/common"
"github.com/aaronchen2k/deeptest/saas/tenant"
"github.com/kataras/iris/v12"
"github.com/snowlyg/multi"
"go.uber.org/zap"
)
type SummaryCtrl struct {
SummaryService *service.SummaryService `inject:""`
BaseCtrl
}
func (c *SummaryCtrl) Summary() {
//SAAS
if config.CONFIG.Saas.Switch {
tenants := tenant.NewTenant().GetInfos()
for _, tenant := range tenants {
go common.AsyncCatchErrRun(func() {
c.SummaryService.Collection(tenant.Id)
})
}
} else { //default
c.SummaryService.Collection("")
}
}
// Card
// @Tags 汇总
// @summary 汇总卡片位信息
// @accept application/json
// @Produce application/json
// @Param Authorization header string true "Authentication header"
// @Param currProjectId query int true "当前项目ID"
// @Param projectId path int true "项目ID"
// @success 200 {object} _domain.Response{data=serverDomain.ResSummaryCard}
// @Router /api/v1/summary/card/{projectId} [get]
func (c *SummaryCtrl) Card(ctx iris.Context) {
tenantId := c.getTenantId(ctx)
projectId, err := ctx.Params().GetInt64("projectId")
if err != nil {
logUtils.Errorf("参数解析失败", zap.String("错误:", err.Error()))
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: _domain.ParamErr.Msg})
return
}
data, err := c.SummaryService.Card(tenantId, projectId)
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.SystemErr.Code, Msg: err.Error()})
return
} else {
ctx.JSON(_domain.Response{Code: _domain.NoErr.Code, Data: data, Msg: _domain.NoErr.Msg})
return
}
}
// Bugs
// @Tags 汇总
// @summary 汇总bug信息
// @accept application/json
// @Produce application/json
// @Param Authorization header string true "Authentication header"
// @Param currProjectId query int true "当前项目ID"
// @Param projectId path int true "项目ID"
// @success 200 {object} _domain.Response{data=serverDomain.ResSummaryBugs}
// @Router /api/v1/summary/bugs/{projectId} [get]
func (c *SummaryCtrl) Bugs(ctx iris.Context) {
tenantId := c.getTenantId(ctx)
projectId, err := ctx.Params().GetInt64("projectId")
if err != nil {
logUtils.Errorf("参数解析失败", zap.String("错误:", err.Error()))
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: _domain.ParamErr.Msg})
return
}
data, err := c.SummaryService.Bugs(tenantId, projectId)
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.SystemErr.Code, Msg: err.Error()})
return
} else {
ctx.JSON(_domain.Response{Code: _domain.NoErr.Code, Data: data, Msg: _domain.NoErr.Msg})
return
}
}
// Details
// @Tags 汇总
// @summary 汇总项目详情
// @accept application/json
// @Produce application/json
// @Param Authorization header string true "Authentication header"
// @Param currProjectId query int true "当前项目ID"
// @success 200 {object} _domain.Response{data=serverDomain.ResSummaryDetail}
// @Router /api/v1/summary/details [get]
func (c *SummaryCtrl) Details(ctx iris.Context) {
tenantId := c.getTenantId(ctx)
userId := multi.GetUserId(ctx)
engineering := ctx.URLParamDefault("engineering", "")
if userId == 0 {
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: "userId为0,或获取userId失败"})
return
}
data, err := c.SummaryService.Details(tenantId, int64(userId), engineering)
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.SystemErr.Code, Msg: err.Error()})
return
} else {
ctx.JSON(_domain.Response{Code: _domain.NoErr.Code, Data: data, Msg: _domain.NoErr.Msg})
return
}
}
// ProjectUserRanking
// @Tags 汇总
// @summary 汇总项目用户排行数据
// @accept application/json
// @Produce application/json
// @Param Authorization header string true "Authentication header"
// @Param currProjectId query int true "当前项目ID"
// @Param cycle path int true "cycle"
// @Param projectId path int true "项目ID"
// @success 200 {object} _domain.Response{data=serverDomain.ResRankingList}
// @Router /api/v1/summary/projectUserRanking/{cycle}/{projectId} [get]
func (c *SummaryCtrl) ProjectUserRanking(ctx iris.Context) {
tenantId := c.getTenantId(ctx)
cycle, err := ctx.Params().GetInt64("cycle")
projectId, err := ctx.Params().GetInt64("projectId")
if err != nil {
logUtils.Errorf("参数解析失败", zap.String("错误:", err.Error()))
ctx.JSON(_domain.Response{Code: _domain.ParamErr.Code, Msg: _domain.ParamErr.Msg})
return
}
data, err := c.SummaryService.ProjectUserRanking(tenantId, cycle, projectId)
if err != nil {
ctx.JSON(_domain.Response{Code: _domain.SystemErr.Code, Msg: err.Error()})
return
} else {
ctx.JSON(_domain.Response{Code: _domain.NoErr.Code, Data: data, Msg: _domain.NoErr.Msg})
return
}
}
// Collection
// @Tags 汇总
// @summary 汇总数据
// @accept application/json
// @Produce application/json
// @Param Authorization header string true "Authentication header"
// @Param currProjectId query int true "当前项目ID"
// @Param store path string true "string"
// @success 200 {object} _domain.Response
// @Router /api/v1/summary/collection/{store} [get]
func (c *SummaryCtrl) Collection(ctx iris.Context) {
tenantId := c.getTenantId(ctx)
name := ctx.Params().GetString("store")
switch name {
case "details":
c.SummaryService.CollectionDetails(tenantId)
case "ranking":
c.SummaryService.CollectionRanking(tenantId)
case "bugs":
c.SummaryService.CollectionBugs(tenantId)
}
ctx.JSON(_domain.Response{Code: _domain.NoErr.Code, Data: "", Msg: _domain.NoErr.Msg})
return
}