|
@@ -1,7 +1,6 @@
|
1
|
1
|
package admin_api_controllers
|
2
|
2
|
|
3
|
3
|
import (
|
4
|
|
- "XT_Admin_Api/models"
|
5
|
4
|
"XT_Admin_Api/models/admin_models"
|
6
|
5
|
"XT_Admin_Api/service"
|
7
|
6
|
"XT_Admin_Api/utils"
|
|
@@ -10,460 +9,6 @@ import (
|
10
|
9
|
|
11
|
10
|
type AnalysisAPIController struct {
|
12
|
11
|
AdminBaseAPIAuthController
|
13
|
|
- // AdminBaseAPIController
|
14
|
|
-}
|
15
|
|
-
|
16
|
|
-// /admin/api/org/regist [get] RegistOrg
|
17
|
|
-func (this *AnalysisAPIController) RegistOrg() {
|
18
|
|
- totalOrg, getTotalOrgErr := service.GetTotalOrgCount()
|
19
|
|
- if getTotalOrgErr != nil {
|
20
|
|
- this.ErrorLog("获取总机构数失败:%v", getTotalOrgErr)
|
21
|
|
- }
|
22
|
|
-
|
23
|
|
- now := time.Now()
|
24
|
|
- zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
|
25
|
|
- registOrgCountToday, getRegistOrgCountTodayErr := service.GetRegistedOrgCountFromDayToDay(zeroHourTimeOfToday, now)
|
26
|
|
- if getRegistOrgCountTodayErr != nil {
|
27
|
|
- this.ErrorLog("获取今日注册机构数失败:%v", getRegistOrgCountTodayErr)
|
28
|
|
- }
|
29
|
|
-
|
30
|
|
- monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
|
31
|
|
- registOrgCountThisWeek, getRegistOrgCountThisWeekErr := service.GetRegistedOrgCountFromDayToDay(monday, sunday)
|
32
|
|
- if getRegistOrgCountThisWeekErr != nil {
|
33
|
|
- this.ErrorLog("获取本周注册机构数失败:%v", getRegistOrgCountThisWeekErr)
|
34
|
|
- }
|
35
|
|
-
|
36
|
|
- thisYear := now.Year()
|
37
|
|
- thisMonth := int(now.Month())
|
38
|
|
- beginningOfMonth, endOfMonth := utils.MonthBeginningToEnd(thisYear, thisMonth)
|
39
|
|
- registOrgCountThisMonth, getRegistOrgCountThisMonthErr := service.GetRegistedOrgCountFromDayToDay(beginningOfMonth, endOfMonth)
|
40
|
|
- if getRegistOrgCountThisMonthErr != nil {
|
41
|
|
- this.ErrorLog("获取本月注册机构数失败:%v", getRegistOrgCountThisMonthErr)
|
42
|
|
- }
|
43
|
|
-
|
44
|
|
- monthRegistOrgCounts := make([]map[string]interface{}, 0, 12)
|
45
|
|
- for m := 1; m < 12; m++ {
|
46
|
|
- if m > thisMonth {
|
47
|
|
- break
|
48
|
|
- }
|
49
|
|
- if m == thisMonth {
|
50
|
|
- monthRegistOrgCounts = append(monthRegistOrgCounts, map[string]interface{}{
|
51
|
|
- "month": m,
|
52
|
|
- "count": registOrgCountThisMonth,
|
53
|
|
- })
|
54
|
|
-
|
55
|
|
- } else {
|
56
|
|
- BOM, EOM := utils.MonthBeginningToEnd(thisYear, m)
|
57
|
|
- registOrgCount, getRegistOrgCountErr := service.GetRegistedOrgCountFromDayToDay(BOM, EOM)
|
58
|
|
- if getRegistOrgCountErr != nil {
|
59
|
|
- this.ErrorLog("获取%v月注册机构数失败:%v", m, getRegistOrgCountErr)
|
60
|
|
- }
|
61
|
|
- monthRegistOrgCounts = append(monthRegistOrgCounts, map[string]interface{}{
|
62
|
|
- "month": m,
|
63
|
|
- "count": registOrgCount,
|
64
|
|
- })
|
65
|
|
- }
|
66
|
|
- }
|
67
|
|
-
|
68
|
|
- registOrgsThisWeek, getRegistOrgThisWeekErr := service.GetRegistedOrgsFromDayToDay(monday, sunday)
|
69
|
|
- if getRegistOrgThisWeekErr != nil {
|
70
|
|
- this.ErrorLog("获取本周注册机构失败:%v", getRegistOrgThisWeekErr)
|
71
|
|
- registOrgsThisWeek = make([]*models.Org, 0)
|
72
|
|
- }
|
73
|
|
-
|
74
|
|
- registOrgsThisMonth, getRegistOrgThisMonthErr := service.GetRegistedOrgsFromDayToDay(beginningOfMonth, endOfMonth)
|
75
|
|
- if getRegistOrgThisMonthErr != nil {
|
76
|
|
- this.ErrorLog("获取本月注册机构失败:%v", getRegistOrgThisMonthErr)
|
77
|
|
- registOrgsThisMonth = make([]*models.Org, 0)
|
78
|
|
- }
|
79
|
|
-
|
80
|
|
- this.ServeSuccessJSON(map[string]interface{}{
|
81
|
|
- "total_org_count": totalOrg,
|
82
|
|
- "regist_org_count_today": registOrgCountToday,
|
83
|
|
- "regist_org_count_week": registOrgCountThisWeek,
|
84
|
|
- "regist_org_count_month": registOrgCountThisMonth,
|
85
|
|
- "regist_org_count_months": monthRegistOrgCounts,
|
86
|
|
- "regist_orgs_week": registOrgsThisWeek,
|
87
|
|
- "regist_orgs_month": registOrgsThisMonth,
|
88
|
|
- })
|
89
|
|
-}
|
90
|
|
-
|
91
|
|
-// /admin/api/org/active [get] ActiveOrg
|
92
|
|
-func (this *AnalysisAPIController) ActiveOrg() {
|
93
|
|
- now := time.Now()
|
94
|
|
- zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
|
95
|
|
- activeOrgCountToday, getActiveTodayErr := service.GetActiveOrgCountFromDayToDay(zeroHourTimeOfToday, now)
|
96
|
|
- if getActiveTodayErr != nil {
|
97
|
|
- this.ErrorLog("获取今日活跃机构数失败:%v", getActiveTodayErr)
|
98
|
|
- }
|
99
|
|
-
|
100
|
|
- monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
|
101
|
|
- activeOrgCountThisWeek, getActiveOrgCountThisWeekErr := service.GetActiveOrgCountFromDayToDay(monday, sunday)
|
102
|
|
- if getActiveOrgCountThisWeekErr != nil {
|
103
|
|
- this.ErrorLog("获取本周活跃机构数失败:%v", getActiveOrgCountThisWeekErr)
|
104
|
|
- }
|
105
|
|
-
|
106
|
|
- thisYear := now.Year()
|
107
|
|
- thisMonth := int(now.Month())
|
108
|
|
- beginningOfMonth, endOfMonth := utils.MonthBeginningToEnd(thisYear, thisMonth)
|
109
|
|
- activeOrgCountThisMonth, getActiveOrgCountThisMonthErr := service.GetActiveOrgCountFromDayToDay(beginningOfMonth, endOfMonth)
|
110
|
|
- if getActiveOrgCountThisMonthErr != nil {
|
111
|
|
- this.ErrorLog("获取本月活跃机构数失败:%v", getActiveOrgCountThisMonthErr)
|
112
|
|
- }
|
113
|
|
-
|
114
|
|
- monthActiveOrgCounts := make([]map[string]interface{}, 0, 12)
|
115
|
|
- for m := 1; m < 12; m++ {
|
116
|
|
- if m > thisMonth {
|
117
|
|
- break
|
118
|
|
- }
|
119
|
|
- if m == thisMonth {
|
120
|
|
- monthActiveOrgCounts = append(monthActiveOrgCounts, map[string]interface{}{
|
121
|
|
- "month": m,
|
122
|
|
- "count": activeOrgCountThisMonth,
|
123
|
|
- })
|
124
|
|
-
|
125
|
|
- } else {
|
126
|
|
- BOM, EOM := utils.MonthBeginningToEnd(thisYear, m)
|
127
|
|
- activeOrgCount, getActiveOrgCountErr := service.GetActiveOrgCountFromDayToDay(BOM, EOM)
|
128
|
|
- if getActiveOrgCountErr != nil {
|
129
|
|
- this.ErrorLog("获取%v月活跃机构数失败:%v", m, getActiveOrgCountErr)
|
130
|
|
- }
|
131
|
|
- monthActiveOrgCounts = append(monthActiveOrgCounts, map[string]interface{}{
|
132
|
|
- "month": m,
|
133
|
|
- "count": activeOrgCount,
|
134
|
|
- })
|
135
|
|
- }
|
136
|
|
- }
|
137
|
|
-
|
138
|
|
- activeOrgsThisWeek, getActiveOrgThisWeekErr := service.GetActiveOrgsFromDayToDay(monday, sunday)
|
139
|
|
- if getActiveOrgThisWeekErr != nil {
|
140
|
|
- this.ErrorLog("获取本周活跃机构失败:%v", getActiveOrgThisWeekErr)
|
141
|
|
- activeOrgsThisWeek = make([]*service.ActiveOrgListVM, 0)
|
142
|
|
- }
|
143
|
|
-
|
144
|
|
- activeOrgsThisMonth, getActiveOrgThisMonthErr := service.GetActiveOrgsFromDayToDay(beginningOfMonth, endOfMonth)
|
145
|
|
- if getActiveOrgThisMonthErr != nil {
|
146
|
|
- this.ErrorLog("获取本月活跃机构失败:%v", getActiveOrgThisMonthErr)
|
147
|
|
- activeOrgsThisMonth = make([]*service.ActiveOrgListVM, 0)
|
148
|
|
- }
|
149
|
|
-
|
150
|
|
- this.ServeSuccessJSON(map[string]interface{}{
|
151
|
|
- "active_org_count_today": activeOrgCountToday,
|
152
|
|
- "active_org_count_week": activeOrgCountThisWeek,
|
153
|
|
- "active_org_count_month": activeOrgCountThisMonth,
|
154
|
|
- "active_org_count_months": monthActiveOrgCounts,
|
155
|
|
- "active_orgs_week": activeOrgsThisWeek,
|
156
|
|
- "active_orgs_month": activeOrgsThisMonth,
|
157
|
|
- })
|
158
|
|
-}
|
159
|
|
-
|
160
|
|
-// /admin/api/user/active [get] ActiveUser
|
161
|
|
-func (this *AnalysisAPIController) ActiveUser() {
|
162
|
|
- now := time.Now()
|
163
|
|
- zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
|
164
|
|
- activeAdminCountToday, getActiveTodayErr := service.GetActiveAdminUserCountFromDayToDay(zeroHourTimeOfToday, now)
|
165
|
|
- if getActiveTodayErr != nil {
|
166
|
|
- this.ErrorLog("获取今日活跃账户数失败:%v", getActiveTodayErr)
|
167
|
|
- }
|
168
|
|
-
|
169
|
|
- monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
|
170
|
|
- activeAdminCountThisWeek, getActiveAdminCountThisWeekErr := service.GetActiveAdminUserCountFromDayToDay(monday, sunday)
|
171
|
|
- if getActiveAdminCountThisWeekErr != nil {
|
172
|
|
- this.ErrorLog("获取本周活跃账户数失败:%v", getActiveAdminCountThisWeekErr)
|
173
|
|
- }
|
174
|
|
-
|
175
|
|
- thisYear := now.Year()
|
176
|
|
- thisMonth := int(now.Month())
|
177
|
|
- beginningOfMonth, endOfMonth := utils.MonthBeginningToEnd(thisYear, thisMonth)
|
178
|
|
- activeAdminCountThisMonth, getActiveAdminCountThisMonthErr := service.GetActiveAdminUserCountFromDayToDay(beginningOfMonth, endOfMonth)
|
179
|
|
- if getActiveAdminCountThisMonthErr != nil {
|
180
|
|
- this.ErrorLog("获取本月活跃账户数失败:%v", getActiveAdminCountThisMonthErr)
|
181
|
|
- }
|
182
|
|
-
|
183
|
|
- monthActiveAdminCounts := make([]map[string]interface{}, 0, 12)
|
184
|
|
- for m := 1; m < 12; m++ {
|
185
|
|
- if m > thisMonth {
|
186
|
|
- break
|
187
|
|
- }
|
188
|
|
- if m == thisMonth {
|
189
|
|
- monthActiveAdminCounts = append(monthActiveAdminCounts, map[string]interface{}{
|
190
|
|
- "month": m,
|
191
|
|
- "count": activeAdminCountThisMonth,
|
192
|
|
- })
|
193
|
|
-
|
194
|
|
- } else {
|
195
|
|
- BOM, EOM := utils.MonthBeginningToEnd(thisYear, m)
|
196
|
|
- activeAdminCount, getActiveAdminCountErr := service.GetActiveAdminUserCountFromDayToDay(BOM, EOM)
|
197
|
|
- if getActiveAdminCountErr != nil {
|
198
|
|
- this.ErrorLog("获取%v月活跃账户数失败:%v", m, getActiveAdminCountErr)
|
199
|
|
- }
|
200
|
|
- monthActiveAdminCounts = append(monthActiveAdminCounts, map[string]interface{}{
|
201
|
|
- "month": m,
|
202
|
|
- "count": activeAdminCount,
|
203
|
|
- })
|
204
|
|
- }
|
205
|
|
- }
|
206
|
|
-
|
207
|
|
- activeAdminsThisWeek, getActiveAdminThisWeekErr := service.GetActiveAdminUsersFromDayToDay(monday, sunday)
|
208
|
|
- if getActiveAdminThisWeekErr != nil {
|
209
|
|
- this.ErrorLog("获取本周活跃账户失败:%v", getActiveAdminThisWeekErr)
|
210
|
|
- activeAdminsThisWeek = make([]*service.ActiveAdminUserListVM, 0)
|
211
|
|
- }
|
212
|
|
-
|
213
|
|
- activeAdminsThisMonth, getActiveAdminThisMonthErr := service.GetActiveAdminUsersFromDayToDay(beginningOfMonth, endOfMonth)
|
214
|
|
- if getActiveAdminThisMonthErr != nil {
|
215
|
|
- this.ErrorLog("获取本月活跃账户失败:%v", getActiveAdminThisMonthErr)
|
216
|
|
- activeAdminsThisMonth = make([]*service.ActiveAdminUserListVM, 0)
|
217
|
|
- }
|
218
|
|
-
|
219
|
|
- this.ServeSuccessJSON(map[string]interface{}{
|
220
|
|
- "active_admin_count_today": activeAdminCountToday,
|
221
|
|
- "active_admin_count_week": activeAdminCountThisWeek,
|
222
|
|
- "active_admin_count_month": activeAdminCountThisMonth,
|
223
|
|
- "active_admin_count_months": monthActiveAdminCounts,
|
224
|
|
- "active_admins_week": activeAdminsThisWeek,
|
225
|
|
- "active_admins_month": activeAdminsThisMonth,
|
226
|
|
- })
|
227
|
|
-}
|
228
|
|
-
|
229
|
|
-// /admin/api/org/expiring [get] ExpiringOrg
|
230
|
|
-func (this *AnalysisAPIController) ExpiringOrg() {
|
231
|
|
- now := time.Now()
|
232
|
|
- zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
|
233
|
|
- // endTimeOfToday := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 999, time.Local)
|
234
|
|
- timeAfter15Days := zeroHourTimeOfToday.AddDate(0, 0, 15)
|
235
|
|
- timeBefore15Days := zeroHourTimeOfToday.AddDate(0, 0, -15)
|
236
|
|
-
|
237
|
|
- countOfWillExpireOrg, getWillExpireOrgCountErr := service.GetWillExpireOrgCountFromDayToDay(zeroHourTimeOfToday, timeAfter15Days)
|
238
|
|
- if getWillExpireOrgCountErr != nil {
|
239
|
|
- this.ErrorLog("获取即将到期机构数失败:%v", getWillExpireOrgCountErr)
|
240
|
|
- }
|
241
|
|
-
|
242
|
|
- countOfExpiredOrg, getExpiredOrgCountErr := service.GetDidExpiredOrgCountFromDayToDay(timeBefore15Days, zeroHourTimeOfToday)
|
243
|
|
- if getExpiredOrgCountErr != nil {
|
244
|
|
- this.ErrorLog("获取刚到期机构数失败:%v", getExpiredOrgCountErr)
|
245
|
|
- }
|
246
|
|
-
|
247
|
|
- willExpireOrgs, getWillExpireOrgsErr := service.GetWillExpireOrgsFromDayToDay(zeroHourTimeOfToday, timeAfter15Days)
|
248
|
|
- if getWillExpireOrgsErr != nil {
|
249
|
|
- this.ErrorLog("获取即将到期机构失败:%v", getWillExpireOrgsErr)
|
250
|
|
- willExpireOrgs = make([]*service.ExpireOrgListVM, 0, 0)
|
251
|
|
- }
|
252
|
|
-
|
253
|
|
- expiredOrgs, getExpiredOrgsErr := service.GetDidExpireOrgsFromDayToDay(timeBefore15Days, zeroHourTimeOfToday)
|
254
|
|
- if getExpiredOrgsErr != nil {
|
255
|
|
- this.ErrorLog("获取已到期机构失败:%v", getExpiredOrgsErr)
|
256
|
|
- expiredOrgs = make([]*service.ExpireOrgListVM, 0, 0)
|
257
|
|
- }
|
258
|
|
-
|
259
|
|
- this.ServeSuccessJSON(map[string]interface{}{
|
260
|
|
- "will_expire_org_count": countOfWillExpireOrg,
|
261
|
|
- "did_expired_org_count": countOfExpiredOrg,
|
262
|
|
- "will_expire_orgs": willExpireOrgs,
|
263
|
|
- "did_expired_orgs": expiredOrgs,
|
264
|
|
- })
|
265
|
|
-}
|
266
|
|
-
|
267
|
|
-// /admin/api/dialysis/analysis [get] DialysisAnalysis
|
268
|
|
-func (this *AnalysisAPIController) DialysisAnalysis() {
|
269
|
|
- now := time.Now()
|
270
|
|
- zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
|
271
|
|
- endTimeOfToday := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 999, time.Local)
|
272
|
|
-
|
273
|
|
- timesToday, getTimesTodayErr := service.GetDialysisTimesFromDayToDay(zeroHourTimeOfToday, endTimeOfToday)
|
274
|
|
- if getTimesTodayErr != nil {
|
275
|
|
- this.ErrorLog("获取今日透析次数失败:%v", getTimesTodayErr)
|
276
|
|
- }
|
277
|
|
-
|
278
|
|
- monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
|
279
|
|
- timesThisWeek, getTimesThisWeekErr := service.GetDialysisTimesFromDayToDay(monday, sunday)
|
280
|
|
- if getTimesThisWeekErr != nil {
|
281
|
|
- this.ErrorLog("获取本周透析次数失败:%v", getTimesThisWeekErr)
|
282
|
|
- }
|
283
|
|
-
|
284
|
|
- thisYear := now.Year()
|
285
|
|
- thisMonth := int(now.Month())
|
286
|
|
- beginningOfMonth, endOfMonth := utils.MonthBeginningToEnd(thisYear, thisMonth)
|
287
|
|
- timesThisMonth, getTimesThisMonthErr := service.GetDialysisTimesFromDayToDay(beginningOfMonth, endOfMonth)
|
288
|
|
- if getTimesThisMonthErr != nil {
|
289
|
|
- this.ErrorLog("获取本月透析次数失败:%v", getTimesThisMonthErr)
|
290
|
|
- }
|
291
|
|
-
|
292
|
|
- monthTimes := make([]map[string]interface{}, 0, 12)
|
293
|
|
- for m := 1; m < 12; m++ {
|
294
|
|
- if m > thisMonth {
|
295
|
|
- break
|
296
|
|
- }
|
297
|
|
- if m == thisMonth {
|
298
|
|
- monthTimes = append(monthTimes, map[string]interface{}{
|
299
|
|
- "month": m,
|
300
|
|
- "count": timesThisMonth,
|
301
|
|
- })
|
302
|
|
-
|
303
|
|
- } else {
|
304
|
|
- BOM, EOM := utils.MonthBeginningToEnd(thisYear, m)
|
305
|
|
- times, getTimesErr := service.GetDialysisTimesFromDayToDay(BOM, EOM)
|
306
|
|
- if getTimesErr != nil {
|
307
|
|
- this.ErrorLog("获取%v月透析次数失败:%v", m, getTimesErr)
|
308
|
|
- }
|
309
|
|
- monthTimes = append(monthTimes, map[string]interface{}{
|
310
|
|
- "month": m,
|
311
|
|
- "count": times,
|
312
|
|
- })
|
313
|
|
- }
|
314
|
|
- }
|
315
|
|
-
|
316
|
|
- this.ServeSuccessJSON(map[string]interface{}{
|
317
|
|
- "times_today": timesToday,
|
318
|
|
- "times_week": timesThisWeek,
|
319
|
|
- "times_month": timesThisMonth,
|
320
|
|
- "times_months": monthTimes,
|
321
|
|
- })
|
322
|
|
-}
|
323
|
|
-
|
324
|
|
-// /admin/api/monitor/analysis [get] MonitorAnalysis
|
325
|
|
-func (this *AnalysisAPIController) MonitorAnalysis() {
|
326
|
|
- now := time.Now()
|
327
|
|
- zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
|
328
|
|
- endTimeOfToday := time.Date(now.Year(), now.Month(), now.Day(), 23, 59, 59, 999, time.Local)
|
329
|
|
-
|
330
|
|
- timesToday, getTimesTodayErr := service.GetMonitoringTimesFromDayToDay(zeroHourTimeOfToday, endTimeOfToday)
|
331
|
|
- if getTimesTodayErr != nil {
|
332
|
|
- this.ErrorLog("获取今日监控次数失败:%v", getTimesTodayErr)
|
333
|
|
- }
|
334
|
|
-
|
335
|
|
- monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
|
336
|
|
- timesThisWeek, getTimesThisWeekErr := service.GetMonitoringTimesFromDayToDay(monday, sunday)
|
337
|
|
- if getTimesThisWeekErr != nil {
|
338
|
|
- this.ErrorLog("获取本周监控次数失败:%v", getTimesThisWeekErr)
|
339
|
|
- }
|
340
|
|
-
|
341
|
|
- thisYear := now.Year()
|
342
|
|
- thisMonth := int(now.Month())
|
343
|
|
- beginningOfMonth, endOfMonth := utils.MonthBeginningToEnd(thisYear, thisMonth)
|
344
|
|
- timesThisMonth, getTimesThisMonthErr := service.GetMonitoringTimesFromDayToDay(beginningOfMonth, endOfMonth)
|
345
|
|
- if getTimesThisMonthErr != nil {
|
346
|
|
- this.ErrorLog("获取本月监控次数失败:%v", getTimesThisMonthErr)
|
347
|
|
- }
|
348
|
|
-
|
349
|
|
- monthTimes := make([]map[string]interface{}, 0, 12)
|
350
|
|
- for m := 1; m < 12; m++ {
|
351
|
|
- if m > thisMonth {
|
352
|
|
- break
|
353
|
|
- }
|
354
|
|
- if m == thisMonth {
|
355
|
|
- monthTimes = append(monthTimes, map[string]interface{}{
|
356
|
|
- "month": m,
|
357
|
|
- "count": timesThisMonth,
|
358
|
|
- })
|
359
|
|
-
|
360
|
|
- } else {
|
361
|
|
- BOM, EOM := utils.MonthBeginningToEnd(thisYear, m)
|
362
|
|
- times, getTimesErr := service.GetMonitoringTimesFromDayToDay(BOM, EOM)
|
363
|
|
- if getTimesErr != nil {
|
364
|
|
- this.ErrorLog("获取%v月监控次数失败:%v", m, getTimesErr)
|
365
|
|
- }
|
366
|
|
- monthTimes = append(monthTimes, map[string]interface{}{
|
367
|
|
- "month": m,
|
368
|
|
- "count": times,
|
369
|
|
- })
|
370
|
|
- }
|
371
|
|
- }
|
372
|
|
-
|
373
|
|
- this.ServeSuccessJSON(map[string]interface{}{
|
374
|
|
- "times_today": timesToday,
|
375
|
|
- "times_week": timesThisWeek,
|
376
|
|
- "times_month": timesThisMonth,
|
377
|
|
- "times_months": monthTimes,
|
378
|
|
- })
|
379
|
|
-}
|
380
|
|
-
|
381
|
|
-// /admin/api/patient/analysis [get] PatientAnalysis
|
382
|
|
-func (this *AnalysisAPIController) PatientAnalysis() {
|
383
|
|
- now := time.Now()
|
384
|
|
- zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
|
385
|
|
- newCountToday, getNewCountTodayErr := service.GetNewPatientCountFromDayToDay(zeroHourTimeOfToday, now)
|
386
|
|
- if getNewCountTodayErr != nil {
|
387
|
|
- this.ErrorLog("获取今日新增病人数失败:%v", getNewCountTodayErr)
|
388
|
|
- }
|
389
|
|
-
|
390
|
|
- monday, sunday := utils.GetMondayAndSundayOfWeekDate(&now)
|
391
|
|
- newCountThisWeek, getNewCountThisWeekErr := service.GetNewPatientCountFromDayToDay(monday, sunday)
|
392
|
|
- if getNewCountThisWeekErr != nil {
|
393
|
|
- this.ErrorLog("获取本周新增病人数失败:%v", getNewCountThisWeekErr)
|
394
|
|
- }
|
395
|
|
-
|
396
|
|
- thisYear := now.Year()
|
397
|
|
- thisMonth := int(now.Month())
|
398
|
|
- beginningOfMonth, endOfMonth := utils.MonthBeginningToEnd(thisYear, thisMonth)
|
399
|
|
- newCountThisMonth, getNewCountThisMonthErr := service.GetNewPatientCountFromDayToDay(beginningOfMonth, endOfMonth)
|
400
|
|
- if getNewCountThisMonthErr != nil {
|
401
|
|
- this.ErrorLog("获取本月新增病人数失败:%v", getNewCountThisMonthErr)
|
402
|
|
- }
|
403
|
|
-
|
404
|
|
- monthNewCounts := make([]map[string]interface{}, 0, 12)
|
405
|
|
- for m := 1; m < 12; m++ {
|
406
|
|
- if m > thisMonth {
|
407
|
|
- break
|
408
|
|
- }
|
409
|
|
- if m == thisMonth {
|
410
|
|
- monthNewCounts = append(monthNewCounts, map[string]interface{}{
|
411
|
|
- "month": m,
|
412
|
|
- "count": newCountThisMonth,
|
413
|
|
- })
|
414
|
|
-
|
415
|
|
- } else {
|
416
|
|
- BOM, EOM := utils.MonthBeginningToEnd(thisYear, m)
|
417
|
|
- newCount, getNewCountErr := service.GetNewPatientCountFromDayToDay(BOM, EOM)
|
418
|
|
- if getNewCountErr != nil {
|
419
|
|
- this.ErrorLog("获取%v月新增病人数失败:%v", m, getNewCountErr)
|
420
|
|
- }
|
421
|
|
- monthNewCounts = append(monthNewCounts, map[string]interface{}{
|
422
|
|
- "month": m,
|
423
|
|
- "count": newCount,
|
424
|
|
- })
|
425
|
|
- }
|
426
|
|
- }
|
427
|
|
-
|
428
|
|
- maleCount, femaleCount, unknowGenderCount, getGenderCountErr := service.GetPatientGenderDistribution()
|
429
|
|
- if getGenderCountErr != nil {
|
430
|
|
- this.ErrorLog("获取病人性别分布失败:%v", getGenderCountErr)
|
431
|
|
- }
|
432
|
|
-
|
433
|
|
- // 1乙肝 2丙肝 3艾滋病 4肺结核 5梅毒
|
434
|
|
- // 不写错误日志了,累了
|
435
|
|
- normalPCount, _ := service.GetInfectiousDiseasePatientCount(0)
|
436
|
|
- type1PCount, _ := service.GetInfectiousDiseasePatientCount(1)
|
437
|
|
- type2PCount, _ := service.GetInfectiousDiseasePatientCount(2)
|
438
|
|
- type3PCount, _ := service.GetInfectiousDiseasePatientCount(3)
|
439
|
|
- type4PCount, _ := service.GetInfectiousDiseasePatientCount(4)
|
440
|
|
- type5PCount, _ := service.GetInfectiousDiseasePatientCount(5)
|
441
|
|
-
|
442
|
|
- ageDistribution, getAgeDistributionErr := service.GetPatientAgeDistribution()
|
443
|
|
- if getAgeDistributionErr != nil {
|
444
|
|
- this.ErrorLog("获取病人年龄分布失败:%v", getAgeDistributionErr)
|
445
|
|
- ageDistribution = make([]*service.PatientAgeCountStruct, 0, 0)
|
446
|
|
- }
|
447
|
|
-
|
448
|
|
- this.ServeSuccessJSON(map[string]interface{}{
|
449
|
|
- "new_patient_count_today": newCountToday,
|
450
|
|
- "new_patient_count_week": newCountThisWeek,
|
451
|
|
- "new_patient_count_month": newCountThisMonth,
|
452
|
|
- "new_patient_count_months": monthNewCounts,
|
453
|
|
-
|
454
|
|
- "male_count": maleCount,
|
455
|
|
- "female_count": femaleCount,
|
456
|
|
- "total_count": maleCount + femaleCount + unknowGenderCount,
|
457
|
|
-
|
458
|
|
- "disease_type_0_count": normalPCount,
|
459
|
|
- "disease_type_1_count": type1PCount,
|
460
|
|
- "disease_type_2_count": type2PCount,
|
461
|
|
- "disease_type_3_count": type3PCount,
|
462
|
|
- "disease_type_4_count": type4PCount,
|
463
|
|
- "disease_type_5_count": type5PCount,
|
464
|
|
-
|
465
|
|
- "age_counts": ageDistribution,
|
466
|
|
- })
|
467
|
12
|
}
|
468
|
13
|
|
469
|
14
|
func (this *AnalysisAPIController) HomeStatistics() {
|
|
@@ -486,15 +31,11 @@ func (this *AnalysisAPIController) HomeStatistics() {
|
486
|
31
|
now := time.Now().Unix()
|
487
|
32
|
|
488
|
33
|
newOrgCount, _ := service.GetRegistedOrgCount(rangeTimeStamp, now)
|
489
|
|
-
|
490
|
34
|
totalOrg, _ := service.GetTotalOrgCount()
|
491
|
|
-
|
492
|
35
|
activeOrgCount, _ := service.GetActiveOrgCount(rangeTimeStamp, now)
|
493
|
36
|
totalActiveOrg, _ := service.GetActiveOrgTotalCount()
|
494
|
|
-
|
495
|
37
|
activeAdminCount, _ := service.GetActiveAdminUserCount(rangeTimeStamp, now)
|
496
|
38
|
adminTotalCount, _ := service.GetAdminUserTotalCount()
|
497
|
|
-
|
498
|
39
|
patientCount, _ := service.GetNewPatientCount(rangeTimeStamp, now)
|
499
|
40
|
patientTotalCount, _ := service.GetPatientTotalCount()
|
500
|
41
|
|