@@ -103,7 +103,6 @@ func (ds *dashboardService) Statistical(ctx context.Context) (*schema.DashboardI
103
103
dashboardInfo := ds .getFromCache (ctx )
104
104
if dashboardInfo == nil {
105
105
dashboardInfo = & schema.DashboardInfo {}
106
- dashboardInfo .QuestionCount = ds .questionCount (ctx )
107
106
dashboardInfo .AnswerCount = ds .answerCount (ctx )
108
107
dashboardInfo .CommentCount = ds .commentCount (ctx )
109
108
dashboardInfo .UserCount = ds .userCount (ctx )
@@ -121,6 +120,18 @@ func (ds *dashboardService) Statistical(ctx context.Context) (*schema.DashboardI
121
120
dashboardInfo .DatabaseSize = ds .GetDatabaseSize ()
122
121
}
123
122
123
+ dashboardInfo .QuestionCount = ds .questionCount (ctx )
124
+ dashboardInfo .UnansweredCount = ds .unansweredQuestionCount (ctx )
125
+ dashboardInfo .ResolvedCount = ds .resolvedQuestionCount (ctx )
126
+
127
+ if dashboardInfo .QuestionCount == 0 {
128
+ dashboardInfo .ResolvedRate = "0.00"
129
+ dashboardInfo .UnansweredRate = "0.00"
130
+ } else {
131
+ dashboardInfo .ResolvedRate = fmt .Sprintf ("%.2f" , float64 (dashboardInfo .ResolvedCount )/ float64 (dashboardInfo .QuestionCount )* 100 )
132
+ dashboardInfo .UnansweredRate = fmt .Sprintf ("%.2f" , float64 (dashboardInfo .UnansweredCount )/ float64 (dashboardInfo .QuestionCount )* 100 )
133
+ }
134
+
124
135
dashboardInfo .ReportCount = ds .reportCount (ctx )
125
136
dashboardInfo .SMTP = ds .smtpStatus (ctx )
126
137
dashboardInfo .HTTPS = ds .httpsStatus (ctx )
@@ -170,6 +181,22 @@ func (ds *dashboardService) questionCount(ctx context.Context) int64 {
170
181
return questionCount
171
182
}
172
183
184
+ func (ds * dashboardService ) unansweredQuestionCount (ctx context.Context ) int64 {
185
+ unansweredQuestionCount , err := ds .questionRepo .GetUnansweredQuestionCount (ctx )
186
+ if err != nil {
187
+ log .Errorf ("get unanswered question count failed: %s" , err )
188
+ }
189
+ return unansweredQuestionCount
190
+ }
191
+
192
+ func (ds * dashboardService ) resolvedQuestionCount (ctx context.Context ) int64 {
193
+ resolvedQuestionCount , err := ds .questionRepo .GetResolvedQuestionCount (ctx )
194
+ if err != nil {
195
+ log .Errorf ("get resolved question count failed: %s" , err )
196
+ }
197
+ return resolvedQuestionCount
198
+ }
199
+
173
200
func (ds * dashboardService ) answerCount (ctx context.Context ) int64 {
174
201
answerCount , err := ds .answerRepo .GetAnswerCount (ctx )
175
202
if err != nil {
0 commit comments