csx 5 gadus atpakaļ
vecāks
revīzija
832b6294bb

+ 0 - 459
controllers/admin_api_controllers/analysis_api_controller.go Parādīt failu

@@ -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
 

+ 3 - 1
controllers/admin_api_controllers/org_api_controller.go Parādīt failu

@@ -55,7 +55,7 @@ func (this *OrgAPIController) GetOrgList() {
55 55
 		endTime = theTime.Unix()
56 56
 	}
57 57
 
58
-	list, err, total := service.GetAllOrgList(active_status, depth_active_status, startTime, endTime, province, city, district, follow, keyword, page, limit)
58
+	list, err, total := service.GetAllOrgList(active_status, depth_active_status, startTime, endTime, province, city, district, follow, keyword, page, limit, this.GetAdminInfo().Admin.IsSuperAdmin)
59 59
 	if err != nil {
60 60
 
61 61
 	} else {
@@ -210,10 +210,12 @@ func (c *OrgAPIController) GetDistrictsByUpid() {
210 210
 func (this *OrgAPIController) GetInitData() {
211 211
 	provinces, _ := service.GetDistrictsByUpid(0)
212 212
 	follower, _ := service.FindAllFollower()
213
+	orgType, _ := service.GetAllOrgType()
213 214
 
214 215
 	this.ServeSuccessJSON(map[string]interface{}{
215 216
 		"provinces": provinces,
216 217
 		"follower":  follower,
218
+		"org_type":  orgType,
217 219
 	})
218 220
 }
219 221
 

+ 0 - 3
controllers/admin_api_controllers/system_api_controller.go Parādīt failu

@@ -77,11 +77,8 @@ func (this *SystemApiController) ModifyAdminUser() {
77 77
 		if info.ID > 0 {
78 78
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNameException)
79 79
 			return
80
-
81 80
 		}
82
-
83 81
 	}
84
-
85 82
 	err := service.UpdateAdmin(admin)
86 83
 	if err == nil {
87 84
 		this.ServeSuccessJSON(map[string]interface{}{

+ 1 - 0
models/org_models.go Parādīt failu

@@ -31,6 +31,7 @@ type Org struct {
31 31
 	AdminUserLoginLog AdminUserLoginLog `gorm:"ForeignKey:OrgId" json:"log"`
32 32
 	AdminUser         AdminUser         `gorm:"ForeignKey:Id;AssociationForeignKey:Creator" json:"admin"`
33 33
 	OrgFollow         []*OrgFollow      `gorm:"ForeignKey:OrgId" json:"follow"`
34
+	Citys             District          `gorm:"ForeignKey:Id;AssociationForeignKey:City" json:"citys"`
34 35
 }
35 36
 
36 37
 func (Org) TableName() string {

+ 1 - 1
routers/router.go Parādīt failu

@@ -10,7 +10,7 @@ import (
10 10
 func init() {
11 11
 	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
12 12
 		// AllowAllOrigins:  true,
13
-		AllowOrigins:     []string{"http://api.szjkhd.com", "http://admin.xt.test.szjkhd.com", "http://localhost:9527"},
13
+		AllowOrigins:     []string{"http://api.szjkhd.com", "http://admin.xt.test.szjkhd.com", "http://admin.xt.szjkhd.com", "http://localhost:9527"},
14 14
 		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
15 15
 		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
16 16
 		ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},

+ 42 - 326
service/admin_service.go Parādīt failu

@@ -7,10 +7,8 @@ import (
7 7
 	"XT_Admin_Api/models/admin_models"
8 8
 	"database/sql"
9 9
 	"fmt"
10
-	"strings"
11
-	"time"
12
-
13 10
 	"github.com/jinzhu/gorm"
11
+	"strings"
14 12
 )
15 13
 
16 14
 func GetAdminAccount(account string, password string) (*admin_models.AdminAccount, error) {
@@ -35,270 +33,6 @@ func GetTotalOrgCount() (int, error) {
35 33
 	return count, nil
36 34
 }
37 35
 
38
-// 获取一段时间内注册的机构数量
39
-func GetRegistedOrgCountFromDayToDay(from time.Time, to time.Time) (int, error) {
40
-	var count int
41
-	err := readUserDb.Model(&models.Org{}).Where("status <> 0 AND ctime >= ? AND ctime <= ?", from.Unix(), to.Unix()).Count(&count).Error
42
-	if err != nil {
43
-		return 0, err
44
-	}
45
-	return count, nil
46
-}
47
-
48
-// 获取一段时间内注册的机构
49
-func GetRegistedOrgsFromDayToDay(from time.Time, to time.Time) ([]*models.Org, error) {
50
-	var orgs []*models.Org
51
-	err := readUserDb.Model(&models.Org{}).Where("status <> 0 AND ctime >= ? AND ctime <= ?", from.Unix(), to.Unix()).Find(&orgs).Error
52
-	if err != nil {
53
-		return nil, err
54
-	}
55
-	return orgs, nil
56
-}
57
-
58
-// 获取一段时间内的活跃机构数
59
-func GetActiveOrgCountFromDayToDay(from time.Time, to time.Time) (int, error) {
60
-	var count int
61
-	rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT org_id) AS count FROM sgj_user_admin_login_log WHERE ctime >= ? AND ctime <= ?", from.Unix(), to.Unix()).Rows()
62
-	if err != nil {
63
-		return 0, err
64
-	}
65
-	if rows.Next() {
66
-		rows.Scan(&count)
67
-	}
68
-	return count, nil
69
-}
70
-
71
-type ActiveOrgListVM struct {
72
-	models.Org
73
-	ActiveTime int64 `gorm:"column:active_time" json:"active_time"`
74
-}
75
-
76
-// 获取一段时间内的活跃机构
77
-func GetActiveOrgsFromDayToDay(from time.Time, to time.Time) ([]*ActiveOrgListVM, error) {
78
-	var orgs []*ActiveOrgListVM
79
-	err := readUserDb.Raw("select * from (select log.org_id, org.*, log.ctime as active_time from sgj_user_admin_login_log as log left join sgj_user_org as org on log.org_id = org.id where log.ctime >= ? AND log.ctime <= ? AND org.status <> 0 order by log.ctime desc) as t group by t.org_id;", from.Unix(), to.Unix()).Scan(&orgs).Error
80
-	if err != nil {
81
-		return nil, err
82
-	}
83
-	return orgs, nil
84
-}
85
-
86
-// 获取一段时间内的活跃账户数
87
-func GetActiveAdminUserCountFromDayToDay(from time.Time, to time.Time) (int, error) {
88
-	var count int
89
-	rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT admin_user_id) AS count FROM sgj_user_admin_login_log WHERE ctime >= ? AND ctime <= ? AND operate_type = 1", from.Unix(), to.Unix()).Rows()
90
-	if err != nil {
91
-		return 0, err
92
-	}
93
-	if rows.Next() {
94
-		rows.Scan(&count)
95
-	}
96
-	return count, nil
97
-}
98
-
99
-type ActiveAdminUserListVM struct {
100
-	models.App_Role
101
-	OrgName    string `gorm:"column:org_name" json:"org_name"`
102
-	ActiveTime int64  `gorm:"column:active_time" json:"active_time"`
103
-}
104
-
105
-// 获取一段时间内的活跃账户
106
-func GetActiveAdminUsersFromDayToDay(from time.Time, to time.Time) ([]*ActiveAdminUserListVM, error) {
107
-	var users []*ActiveAdminUserListVM
108
-	err := readUserDb.Raw("select * from (select log.admin_user_id as uid, admin.*, org.org_name, log.ctime as active_time from sgj_user_admin_login_log as log left join sgj_user_admin_role as admin on log.admin_user_id = admin.admin_user_id left join sgj_user_org as org on log.org_id = org.id where log.ctime >= ? AND log.ctime <= ? AND log.operate_type = 1 AND admin.status > 0 order by log.ctime desc) as t group by t.uid;", from.Unix(), to.Unix()).Scan(&users).Error
109
-	if err != nil {
110
-		return nil, err
111
-	}
112
-	return users, nil
113
-}
114
-
115
-// 获取即将到期机构数
116
-func GetWillExpireOrgCountFromDayToDay(from time.Time, to time.Time) (int, error) {
117
-	var count int
118
-	rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT org_id) AS count FROM sgj_serve_subscibe WHERE period_end >= ? AND period_end <= ? AND state <> 9 GROUP BY org_id;", from.Unix(), to.Unix()).Rows()
119
-	if err != nil {
120
-		return 0, err
121
-	}
122
-	if rows.Next() {
123
-		rows.Scan(&count)
124
-	}
125
-	return count, nil
126
-}
127
-
128
-// 获取已到期机构数
129
-func GetDidExpiredOrgCountFromDayToDay(from time.Time, to time.Time) (int, error) {
130
-	var count int
131
-	rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT org_id) AS count FROM sgj_serve_subscibe WHERE period_end >= ? AND period_end <= ? AND state <> 9 GROUP BY org_id;", from.Unix(), to.Unix()).Rows()
132
-	if err != nil {
133
-		return 0, err
134
-	}
135
-	if rows.Next() {
136
-		rows.Scan(&count)
137
-	}
138
-	return count, nil
139
-}
140
-
141
-type ExpireOrgListVM struct {
142
-	OrgID      int64  `gorm:"column:org_id" json:"org_id"`
143
-	OrgName    string `gorm:"column:org_name" json:"org_name"`
144
-	PeriodEnd  int64  `gorm:"column:period_end" json:"period_end"`
145
-	Telephone  string `gorm:"column:telephone" json:"telephone"`
146
-	ExpireDays int    `gorm:"-" json:"expire_days"`
147
-}
148
-
149
-// 获取即将到期机构
150
-func GetWillExpireOrgsFromDayToDay(from time.Time, to time.Time) ([]*ExpireOrgListVM, error) {
151
-	var vms []*ExpireOrgListVM
152
-	err := readUserDb.Raw("select s_o.org_id, s_o.period_end, o.org_name, o.telephone from (select ss.* from (select s.org_id as org_id, s.id as sid, s.period_end from sgj_serve_subscibe as s where s.period_end <= ? AND s.period_end >= ? AND s.state <> 9 order by s.id desc) as ss group by ss.org_id) as s_o left join sgj_user_org as o on o.id = s_o.org_id", to.Unix(), from.Unix()).Scan(&vms).Error
153
-	if err != nil {
154
-		return nil, err
155
-	}
156
-	for _, vm := range vms {
157
-		vm.ExpireDays = time.Unix(vm.PeriodEnd, 0).Day() - from.Day()
158
-	}
159
-	return vms, nil
160
-}
161
-
162
-// 获取已到期机构
163
-func GetDidExpireOrgsFromDayToDay(from time.Time, to time.Time) ([]*ExpireOrgListVM, error) {
164
-	var vms []*ExpireOrgListVM
165
-	err := readUserDb.Raw("select s_o.org_id, s_o.period_end, o.org_name, o.telephone from (select ss.* from (select s.org_id as org_id, s.id as sid, s.period_end from sgj_serve_subscibe as s where s.period_end >= ? AND s.period_end <= ? AND s.state <> 9 order by s.id desc) as ss group by ss.org_id) as s_o left join sgj_user_org as o on o.id = s_o.org_id", from.Unix(), to.Unix()).Scan(&vms).Error
166
-	if err != nil {
167
-		return nil, err
168
-	}
169
-	for _, vm := range vms {
170
-		vm.ExpireDays = to.Day() - time.Unix(vm.PeriodEnd, 0).Day()
171
-	}
172
-	return vms, nil
173
-}
174
-
175
-// 获取一段时间内的透析次数
176
-func GetDialysisTimesFromDayToDay(from time.Time, to time.Time) (int, error) {
177
-	var count int
178
-	err := readDb.Model(&models.DialysisOrder{}).Where("status > 0 AND dialysis_date >= ? AND dialysis_date <= ?", from.Unix(), to.Unix()).Count(&count).Error
179
-	if err != nil {
180
-		return 0, err
181
-	}
182
-	return count, nil
183
-}
184
-
185
-// 获取一段时间内的监控次数
186
-func GetMonitoringTimesFromDayToDay(from time.Time, to time.Time) (int, error) {
187
-	var count int
188
-	err := readDb.Model(&models.MonitoringRecord{}).Where("status > 0 AND monitoring_date >= ? AND monitoring_date <= ?", from.Unix(), to.Unix()).Count(&count).Error
189
-	if err != nil {
190
-		return 0, err
191
-	}
192
-	return count, nil
193
-}
194
-
195
-// 获取一段时间内新增病人数量
196
-func GetNewPatientCountFromDayToDay(from time.Time, to time.Time) (int, error) {
197
-	var count int
198
-	err := readDb.Model(&models.Patients{}).Where("status > 0 AND created_time >= ? AND created_time <= ?", from.Unix(), to.Unix()).Count(&count).Error
199
-	if err != nil {
200
-		return 0, err
201
-	}
202
-	return count, nil
203
-}
204
-
205
-// 获取病人性别分布
206
-func GetPatientGenderDistribution() (int, int, int, error) {
207
-	var maleCount, femaleCount, unknowGenderCount int
208
-	rows, err := readDb.Raw("SELECT count(id), gender FROM xt_patients WHERE (status > 0) group by gender;").Rows()
209
-	if err != nil {
210
-		return 0, 0, 0, err
211
-	}
212
-	for rows.Next() {
213
-		var gender, count int
214
-		rows.Scan(&count, &gender)
215
-		if gender == 1 {
216
-			maleCount = count
217
-		} else if gender == 2 {
218
-			femaleCount = count
219
-		} else {
220
-			unknowGenderCount = count
221
-		}
222
-	}
223
-	return maleCount, femaleCount, unknowGenderCount, nil
224
-}
225
-
226
-// 获取某种传染病的病人数,diseaseType = 0时为没有传染病
227
-// 1乙肝 2丙肝 3艾滋病 4肺结核 5梅毒
228
-func GetInfectiousDiseasePatientCount(diseaseType int) (int, error) {
229
-	if diseaseType == 0 {
230
-		var count int
231
-		rows, err := readDb.Raw("select count(p.id) from xt_patients as p where id not in (select p_d.patient_id from xt_patients_infectious_diseases as p_d where status = 1 group by p_d.patient_id) and status = 1;").Rows()
232
-		if err != nil {
233
-			return 0, err
234
-		}
235
-		if rows.Next() {
236
-			rows.Scan(&count)
237
-		}
238
-		return count, nil
239
-
240
-	} else {
241
-		var count int
242
-		rows, err := readDb.Raw("select count(distinct patient_id) from xt_patients_infectious_diseases where status = 1 and disease_id = ?;", diseaseType).Rows()
243
-		if err != nil {
244
-			return 0, err
245
-		}
246
-		if rows.Next() {
247
-			rows.Scan(&count)
248
-		}
249
-		return count, nil
250
-	}
251
-}
252
-
253
-// 获取患者年龄分布
254
-func GetPatientAgeDistribution() ([]*PatientAgeCountStruct, error) {
255
-	var counts []*PatientAgeCountStruct
256
-	err := readDb.Raw(`SELECT nnd AS 'age',COUNT(*) AS 'count' FROM (
257
-		SELECT
258
-			CASE
259
-				WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d'))<10 THEN '10'
260
-				WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=10 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<20 THEN '20'
261
-				WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=20 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<30 THEN '30'
262
-				WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=30 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<40 THEN '40'
263
-				WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=40 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<50 THEN '50'
264
-				WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=50 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<60 THEN '60'
265
-				WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=60 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<70 THEN '70'
266
-				WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=70 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<80 THEN '80'
267
-				WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=80 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<90 THEN '90'
268
-				WHEN (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )>=90 AND (YEAR(NOW())-DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%Y')-1) + (DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL birthday SECOND),'%m%d') <= DATE_FORMAT(NOW(), '%m%d') )<100 THEN '100'
269
-				ELSE '-1'
270
-			END
271
-		AS nnd FROM xt_patients where status=1
272
-	) a GROUP BY nnd;`).Scan(&counts).Error
273
-	if err != nil {
274
-		return nil, err
275
-	}
276
-	return counts, nil
277
-}
278
-
279
-func GetAdminUserElectronicSignature(orgID int64, appID int64, userID int64) (*models.AdminUserElectronicSignature, error) {
280
-	var es models.AdminUserElectronicSignature
281
-	err := readUserDb.Model(&models.AdminUserElectronicSignature{}).Where("org_id=? and app_id=? and creator=? and status=1", orgID, appID, userID).First(&es).Error
282
-
283
-	if err == gorm.ErrRecordNotFound {
284
-		return nil, nil
285
-	}
286
-	if err != nil {
287
-		return nil, err
288
-	}
289
-	return &es, nil
290
-}
291
-
292
-func CreateAdminUserElectronicSignature(es *models.AdminUserElectronicSignature) error {
293
-	err := writeUserDb.Create(es).Error
294
-	return err
295
-}
296
-
297
-func SaveAdminUserElectronicSignature(es *models.AdminUserElectronicSignature) error {
298
-	err := writeUserDb.Save(es).Error
299
-	return err
300
-}
301
-
302 36
 func GetAdminUserSpecialPermission(orgID int64, appID int64, adminUserID int64, permissionType models.SpecialPermissionType) (*models.AdminUserSpecialPermission, error) {
303 37
 	var record models.AdminUserSpecialPermission
304 38
 	err := readDb.Model(&models.AdminUserSpecialPermission{}).Where("org_id = ? AND app_id = ? AND admin_user_id = ? AND permission = ? AND status = 1", orgID, appID, adminUserID, permissionType).First(&record).Error
@@ -312,53 +46,14 @@ func GetAdminUserSpecialPermission(orgID int64, appID int64, adminUserID int64,
312 46
 	return &record, nil
313 47
 }
314 48
 
315
-func SaveAdminUserSpecialPermission(permission *models.AdminUserSpecialPermission) error {
316
-	err := writeDb.Save(permission).Error
317
-	return err
318
-}
319
-
320
-func GetAllValidAdminUsersWithSpecialPermission(orgID int64, appID int64, permissionType models.SpecialPermissionType) ([]*models.AdminUserSpecialPermission, error) {
321
-	var records []*models.AdminUserSpecialPermission
322
-	err := readDb.Model(&models.AdminUserSpecialPermission{}).Where("org_id = ? AND app_id = ? AND permission = ? AND status = 1", orgID, appID, permissionType).Find(&records).Error
323
-	if err != nil {
324
-		return nil, err
325
-	}
326
-	return records, nil
327
-}
328
-
329
-func GetAllSpecialPermissionAdminUsersWithoutStatus(orgID int64, appID int64, permissionType models.SpecialPermissionType) ([]*models.AdminUserSpecialPermission, error) {
330
-	var records []*models.AdminUserSpecialPermission
331
-	err := readDb.Model(&models.AdminUserSpecialPermission{}).Where("org_id = ? AND app_id = ? AND permission = ?", orgID, appID, permissionType).Find(&records).Error
332
-	if err != nil {
333
-		return nil, err
334
-	}
335
-	return records, nil
336
-}
337
-
338
-func CancelAllSpecialPermissionAdminUsers(orgID int64, appID int64, permissionType models.SpecialPermissionType) error {
339
-	tx := writeDb.Begin()
340
-	updateTime := time.Now().Unix()
341
-	err := tx.Model(&models.AdminUserSpecialPermission{}).Where("org_id = ? AND app_id = ? AND status = 1 AND permission = ?", orgID, appID, permissionType).Updates(map[string]interface{}{"status": 0, "mtime": updateTime}).Error
342
-	if err != nil {
343
-		tx.Rollback()
344
-		return err
345
-	}
346
-	tx.Commit()
347
-	return nil
348
-}
349
-
350
-func BatchSaveSpecialPermissionAdminUsers(users []*models.AdminUserSpecialPermission) error {
351
-	tx := writeDb.Begin()
352
-	for _, user := range users {
353
-		tx.Save(user)
354
-	}
355
-	return tx.Commit().Error
356
-}
357
-
358 49
 // 获取一段时间内新增病人数量
359 50
 func GetNewPatientCount(from int64, to int64) (int, error) {
360 51
 	var count int
361
-	rows, err := readDb.Raw("SELECT COUNT(DISTINCT id_card_no) AS count FROM xt_patients WHERE status > 0 AND created_time >= ? AND created_time <= ?", from, to).Rows()
52
+	db := readDb.Raw("SELECT COUNT(DISTINCT id_card_no) AS count FROM xt_patients WHERE status > 0 AND created_time >= ? AND created_time <= ?", from, to)
53
+	rows, err := db.Rows()
54
+	defer rows.Close()
55
+
56
+	//rows, err := readDb.Raw("SELECT COUNT(DISTINCT id_card_no) AS count FROM xt_patients WHERE status > 0 AND created_time >= ? AND created_time <= ?", from, to).Rows()
362 57
 	if err != nil {
363 58
 		return 0, err
364 59
 	}
@@ -372,7 +67,11 @@ func GetNewPatientCount(from int64, to int64) (int, error) {
372 67
 func GetPatientTotalCount() (int64, error) {
373 68
 
374 69
 	var count int64
375
-	rows, err := readDb.Raw("SELECT COUNT(DISTINCT id_card_no) AS count FROM xt_patients").Rows()
70
+	db := readDb.Raw("SELECT COUNT(DISTINCT id_card_no) AS count FROM xt_patients")
71
+	rows, err := db.Rows()
72
+	defer rows.Close()
73
+
74
+	//rows, err := readDb.Raw("SELECT COUNT(DISTINCT id_card_no) AS count FROM xt_patients").Rows()
376 75
 	if err != nil {
377 76
 		return 0, err
378 77
 	}
@@ -386,7 +85,11 @@ func GetPatientTotalCount() (int64, error) {
386 85
 // 获取一段时间内的活跃账户数
387 86
 func GetActiveAdminUserCount(from int64, to int64) (int64, error) {
388 87
 	var count int64
389
-	rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT admin_user_id) AS count FROM sgj_user_admin_login_log WHERE ctime >= ? AND ctime <= ? AND operate_type = 1 AND app_type = 3", from, to).Rows()
88
+	db := readUserDb.Raw("SELECT COUNT(DISTINCT admin_user_id) AS count FROM sgj_user_admin_login_log WHERE ctime >= ? AND ctime <= ? AND operate_type = 1 AND app_type = 3", from, to)
89
+	rows, err := db.Rows()
90
+	defer rows.Close()
91
+
92
+	//rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT admin_user_id) AS count FROM sgj_user_admin_login_log WHERE ctime >= ? AND ctime <= ? AND operate_type = 1 AND app_type = 3", from, to).Rows()
390 93
 	if err != nil {
391 94
 		return 0, err
392 95
 	}
@@ -399,7 +102,11 @@ func GetActiveAdminUserCount(from int64, to int64) (int64, error) {
399 102
 // 获取所有机构账户数量
400 103
 func GetAdminUserTotalCount() (int64, error) {
401 104
 	var count int64
402
-	rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT admin_user_id) AS count FROM sgj_user_admin_login_log WHERE operate_type = 1 AND app_type = 3").Rows()
105
+	db := readUserDb.Raw("SELECT COUNT(DISTINCT admin_user_id) AS count FROM sgj_user_admin_login_log WHERE operate_type = 1 AND app_type = 3")
106
+	rows, err := db.Rows()
107
+	defer rows.Close()
108
+
109
+	//rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT admin_user_id) AS count FROM sgj_user_admin_login_log WHERE operate_type = 1 AND app_type = 3").Rows()
403 110
 	if err != nil {
404 111
 		return 0, err
405 112
 	}
@@ -413,7 +120,8 @@ func GetAdminUserTotalCount() (int64, error) {
413 120
 func GetRegistedOrgCount(from int64, to int64) (int64, error) {
414 121
 
415 122
 	var count int64
416
-	err := readUserDb.Model(&models.Org{}).Where("status <> 0 AND ctime >= ? AND ctime <= ? AND AND import <> 1", from, to).Count(&count).Error
123
+
124
+	err := readUserDb.Model(&models.Org{}).Where("status <> 0 AND ctime >= ? AND ctime <= ? AND  import <> 1", from, to).Count(&count).Error
417 125
 	if err != nil {
418 126
 		return 0, err
419 127
 	}
@@ -423,7 +131,11 @@ func GetRegistedOrgCount(from int64, to int64) (int64, error) {
423 131
 // 获取一段时间内的活跃机构数
424 132
 func GetActiveOrgCount(from int64, to int64) (int64, error) {
425 133
 	var count int64
426
-	rows, err := readDb.Raw("SELECT COUNT(DISTINCT user_org_id) AS count FROM  xt_dialysis_order where  created_time >= ? AND created_time <= ? AND status = 1 ", from, to).Rows()
134
+
135
+	db := readDb.Raw("SELECT COUNT(DISTINCT user_org_id) AS count FROM  xt_dialysis_order where  created_time >= ? AND created_time <= ? AND status = 1 ", from, to)
136
+	rows, err := db.Rows()
137
+	defer rows.Close()
138
+
427 139
 	if err != nil {
428 140
 		return 0, err
429 141
 	}
@@ -436,7 +148,11 @@ func GetActiveOrgCount(from int64, to int64) (int64, error) {
436 148
 // 获取所有活跃机构数
437 149
 func GetActiveOrgTotalCount() (int64, error) {
438 150
 	var count int64
439
-	rows, err := readDb.Raw("SELECT COUNT(DISTINCT user_org_id) AS count FROM sgj_xt.xt_dialysis_order Where status = 1").Rows()
151
+
152
+	db := readDb.Raw("SELECT COUNT(DISTINCT user_org_id) AS count FROM sgj_xt.xt_dialysis_order Where status = 1")
153
+	rows, err := db.Rows()
154
+	defer rows.Close()
155
+	//rows, err := readDb.Raw("SELECT COUNT(DISTINCT user_org_id) AS count FROM sgj_xt.xt_dialysis_order Where status = 1").Rows()
440 156
 	if err != nil {
441 157
 		return 0, err
442 158
 	}
@@ -608,7 +324,7 @@ func CreateAdmin(admin *admin_models.AdminAccount) (err error) {
608 324
 }
609 325
 
610 326
 func FindUserInfoByAccount(account string) (admin admin_models.AdminAccount, err error) {
611
-	err = readUserDb.Model(&admin_models.AdminAccount{}).Where("account = ?", account).First(&admin).Error
327
+	err = readUserDb.Model(&admin_models.AdminAccount{}).Where("account = ? AND status = 1", account).First(&admin).Error
612 328
 	return
613 329
 }
614 330
 
@@ -717,13 +433,13 @@ func GetAllWaitFollowOrgList(keyword string, page int64, limit int64, id int64)
717 433
 	db := readUserDb
718 434
 	if len(keyword) > 0 {
719 435
 		likeKey := "%" + keyword + "%"
720
-		err = db.Raw("Select id, org_name From  sgj_user_org  Where NOT EXISTS (Select id, org_name FROM sgj_org_follow Where sgj_org_follow.org_id = sgj_user_org.id AND sgj_org_follow.admin_user_id = ? AND sgj_org_follow.status = 1 ) AND import <> 1 AND (sgj_user_org.org_name Like ? OR sgj_user_org.org_short_name Like ?)", id, likeKey, likeKey).Offset(offset).Limit(limit).Scan(&orgViewModel).Error
721
-		readUserDb.Raw("Select count(id) as count From  sgj_user_org  Where NOT EXISTS (Select id, org_name FROM sgj_org_follow Where sgj_org_follow.org_id = sgj_user_org.id AND sgj_org_follow.admin_user_id = ? AND sgj_org_follow.status = 1)  AND import <> 1 AND (sgj_user_org.org_name Like ? OR sgj_user_org.org_short_name Like ?)", id, likeKey, likeKey).Scan(&totals)
436
+		err = db.Raw("Select id, org_name From  sgj_user_org  Where NOT EXISTS (Select id, org_name FROM sgj_org_follow Where sgj_org_follow.org_id = sgj_user_org.id AND sgj_org_follow.admin_user_id = ? AND sgj_org_follow.status = 1 ) AND import <> 1 AND (sgj_user_org.org_name Like ? OR sgj_user_org.org_short_name Like ?) AND status = 1 ORDER BY sgj_user_org.ctime DESC", id, likeKey, likeKey).Offset(offset).Limit(limit).Scan(&orgViewModel).Error
437
+		readUserDb.Raw("Select count(id) as count From  sgj_user_org  Where NOT EXISTS (Select id, org_name FROM sgj_org_follow Where sgj_org_follow.org_id = sgj_user_org.id AND sgj_org_follow.admin_user_id = ? AND sgj_org_follow.status = 1)  AND import <> 1 AND (sgj_user_org.org_name Like ? OR sgj_user_org.org_short_name Like ?) AND status = 1", id, likeKey, likeKey).Scan(&totals)
722 438
 
723 439
 	} else {
724
-		db = db.Raw("Select id, org_name From  sgj_user_org  Where NOT EXISTS (Select id, org_name FROM sgj_org_follow Where sgj_org_follow.org_id = sgj_user_org.id AND sgj_org_follow.admin_user_id = ? AND sgj_org_follow.status = 1)  AND import <> 1", id)
440
+		db = db.Raw("Select id, org_name From  sgj_user_org  Where NOT EXISTS (Select id, org_name FROM sgj_org_follow Where sgj_org_follow.org_id = sgj_user_org.id AND sgj_org_follow.admin_user_id = ? AND sgj_org_follow.status = 1)  AND import <> 1 AND status = 1 ORDER BY sgj_user_org.ctime DESC", id)
725 441
 		err = db.Offset(offset).Limit(limit).Scan(&orgViewModel).Error
726
-		readUserDb.Raw("Select count(id) as count From  sgj_user_org  Where NOT EXISTS (Select id, org_name FROM sgj_org_follow Where sgj_org_follow.org_id = sgj_user_org.id AND sgj_org_follow.admin_user_id = ? AND sgj_org_follow.status = 1)  AND import <> 1", id).Scan(&totals)
442
+		readUserDb.Raw("Select count(id) as count From  sgj_user_org  Where NOT EXISTS (Select id, org_name FROM sgj_org_follow Where sgj_org_follow.org_id = sgj_user_org.id AND sgj_org_follow.admin_user_id = ? AND sgj_org_follow.status = 1)  AND import <> 1 AND status = 1", id).Scan(&totals)
727 443
 
728 444
 	}
729 445
 
@@ -743,8 +459,8 @@ func FindAllFollowOrg(keyword string, page int64, limit int64, admin_id int64) (
743 459
 		var rows *sql.Rows
744 460
 		var errs error
745 461
 		likeKey := "%" + keyword + "%"
746
-		rows, errs = readUserDb.Raw("SELECT follow.*, org.org_name as org_name FROM sgj_org_follow as follow join sgj_user_org as org on org.id = follow.org_id AND (org.org_name Like ? OR org.org_short_name Like ?) AND org.import <> 1 WHERE (follow.admin_user_id = ? AND follow.status = 1)", likeKey, likeKey, admin_id).Offset(offset).Limit(limit).Rows()
747
-		readUserDb.Raw("SELECT count(follow.id) as count FROM sgj_org_follow as follow join sgj_user_org as org on org.id = follow.org_id AND (org.org_name Like ? OR org.org_short_name Like ?) AND org.import <> 1  WHERE follow.admin_user_id = ? AND follow.status = 1", likeKey, likeKey, admin_id).Scan(&totals)
462
+		rows, errs = readUserDb.Raw("SELECT follow.*, org.org_name as org_name, org.ctime as time FROM sgj_org_follow as follow join sgj_user_org as org on org.id = follow.org_id AND (org.org_name Like ? OR org.org_short_name Like ?) AND org.import <> 1 AND org.status = 1  WHERE (follow.admin_user_id = ? AND follow.status = 1) ORDER BY time DESC", likeKey, likeKey, admin_id).Offset(offset).Limit(limit).Rows()
463
+		readUserDb.Raw("SELECT count(follow.id) as count FROM sgj_org_follow as follow join sgj_user_org as org on org.id = follow.org_id AND (org.org_name Like ? OR org.org_short_name Like ?) AND org.import <> 1 AND org.status = 1  WHERE follow.admin_user_id = ? AND follow.status = 1", likeKey, likeKey, admin_id).Scan(&totals)
748 464
 
749 465
 		defer rows.Close()
750 466
 		if errs != nil {
@@ -761,8 +477,8 @@ func FindAllFollowOrg(keyword string, page int64, limit int64, admin_id int64) (
761 477
 		var vms []*FollowViewModel = make([]*FollowViewModel, 0)
762 478
 		var rows *sql.Rows
763 479
 		var errs error
764
-		rows, errs = readUserDb.Raw("SELECT follow.*, org.org_name as org_name FROM sgj_org_follow as follow join sgj_user_org as org on org.id = follow.org_id   AND org.import <> 1 WHERE follow.admin_user_id = ? AND follow.status = 1", admin_id).Offset(offset).Limit(limit).Rows()
765
-		readUserDb.Raw("SELECT count(follow.id) as count FROM sgj_org_follow as follow join sgj_user_org as org on org.id = follow.org_id  AND org.import <> 1  WHERE follow.admin_user_id = ? AND follow.status = 1", admin_id).Scan(&totals)
480
+		rows, errs = readUserDb.Raw("SELECT follow.*, org.org_name as org_name, org.ctime as time FROM sgj_org_follow as follow join sgj_user_org as org on org.id = follow.org_id   AND org.import <> 1  AND org.status = 1 WHERE follow.admin_user_id = ? AND follow.status = 1 ORDER BY time DESC", admin_id).Offset(offset).Limit(limit).Rows()
481
+		readUserDb.Raw("SELECT count(follow.id) as count FROM sgj_org_follow as follow join sgj_user_org as org on org.id = follow.org_id  AND org.import <> 1 AND org.status = 1  WHERE follow.admin_user_id = ? AND follow.status = 1", admin_id).Scan(&totals)
766 482
 
767 483
 		defer rows.Close()
768 484
 		if errs != nil {

+ 18 - 8
service/db.go Parādīt failu

@@ -63,35 +63,45 @@ func ConnectDB() {
63 63
 	wudsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4&parseTime=true", writeUserUser, writeUserPass, writeUserHost, writeUserPort, writeUserName)
64 64
 
65 65
 	readDb, err = gorm.Open("mysql", rdsn)
66
+
67
+	//defer readDb.Close()
66 68
 	if err != nil {
67 69
 		//beego.Error(err)
68 70
 	}
69
-	readDb.DB().SetMaxIdleConns(10)
70
-	readDb.DB().SetMaxOpenConns(100)
71
+	readDb.DB().SetMaxIdleConns(5)
72
+	readDb.DB().SetMaxOpenConns(20)
71 73
 	readDb.LogMode(true)
72 74
 
73 75
 	writeDb, err = gorm.Open("mysql", wdsn)
74 76
 	if err != nil {
75 77
 		//beego.Error(err)
76 78
 	}
77
-	writeDb.DB().SetMaxIdleConns(10)
78
-	writeDb.DB().SetMaxOpenConns(100)
79
+
80
+	//defer writeDb.Close()
81
+
82
+	writeDb.DB().SetMaxIdleConns(5)
83
+	writeDb.DB().SetMaxOpenConns(20)
79 84
 	writeDb.LogMode(true)
80 85
 
81 86
 	readUserDb, err = gorm.Open("mysql", rudsn)
82 87
 	if err != nil {
83 88
 		//beego.Error(err)
84 89
 	}
85
-	readUserDb.DB().SetMaxIdleConns(10)
86
-	readUserDb.DB().SetMaxOpenConns(100)
90
+
91
+	//defer readUserDb.Close()
92
+
93
+	readUserDb.DB().SetMaxIdleConns(5)
94
+	readUserDb.DB().SetMaxOpenConns(20)
87 95
 	readUserDb.LogMode(true)
88 96
 
89 97
 	writeUserDb, err = gorm.Open("mysql", wudsn)
90 98
 	if err != nil {
91 99
 		//beego.Error(err)
92 100
 	}
93
-	writeUserDb.DB().SetMaxIdleConns(10)
94
-	writeUserDb.DB().SetMaxOpenConns(100)
101
+	//defer writeUserDb.Close()
102
+
103
+	writeUserDb.DB().SetMaxIdleConns(5)
104
+	writeUserDb.DB().SetMaxOpenConns(20)
95 105
 	writeUserDb.LogMode(true)
96 106
 
97 107
 }

+ 23 - 0
service/function_service.go Parādīt failu

@@ -12,6 +12,7 @@ func GetTodayInfo(to int64, ctime int64, page int64, limit int64) (patientinfo [
12 12
 	err = readUserDb.Raw("select * from sgj_users.sgj_user_org as u left join sgj_org_follow as f On f.org_id = u.id left JoIN sgj_admin as a On a.id = f.admin_user_id left join sgj_xt.xt_patients as x on x.user_org_id = u.id where x.created_time >= ? AND x.created_time <= ?  GROUP BY x.user_org_id", to, ctime).Scan(&patientinfo).Error
13 13
 	rows, err := readUserDb.Offset(offset).Limit(limit).Raw("select Count(1) from sgj_users.sgj_user_org as u join sgj_xt.xt_patients as x on x.user_org_id = u.id where x.created_time >= ? AND x.created_time <= ?", to, ctime).Rows()
14 14
 	fmt.Println("rows是什么", rows)
15
+	defer rows.Close()
15 16
 	if rows.Next() {
16 17
 		rows.Scan(&total)
17 18
 	}
@@ -25,6 +26,8 @@ func GetTodayDialysisPatientsInfo(to int64, ctime int64, page int64, limit int64
25 26
 	offset := (page - 1) * limit
26 27
 	err = readUserDb.Raw("select * from sgj_users.sgj_user_org as u left join sgj_org_follow as f On f.org_id = u.id left JoIN sgj_admin as a On a.id = f.admin_user_id left join sgj_xt.xt_dialysis_prescription as x on x.user_org_id = u.id left JOIN sgj_xt.xt_patients as p On p.id = x.patient_id  where x.created_time >= ? AND x.created_time <= ? GROUP BY x.user_org_id", to, ctime).Scan(&patientinfo).Error
27 28
 	rows, err := readUserDb.Offset(offset).Limit(limit).Raw("select Count(1) from sgj_users.sgj_user_org as u join sgj_xt.xt_dialysis_prescription as x on x.user_org_id = u.id  where x.created_time >= ? AND x.created_time <= ?", to, ctime).Rows()
29
+	defer rows.Close()
30
+
28 31
 	if rows.Next() {
29 32
 		rows.Scan(&total)
30 33
 	}
@@ -38,6 +41,8 @@ func GetTodayReceivePatientsInfo(to int64, ctime int64, page int64, limit int64)
38 41
 	offset := (page - 1) * limit
39 42
 	err = readUserDb.Raw("select * from sgj_users.sgj_user_org as u  left join sgj_org_follow as f On f.org_id = u.id left JoIN sgj_admin as a On a.id = f.admin_user_id left join sgj_xt.xt_receive_treatment_asses as x on x.user_org_id = u.id left JOIN sgj_xt.xt_patients as p On p.id = x.patient_id  where x.created_time >= ? AND x.created_time <= ? GROUP BY x.user_org_id", to, ctime).Scan(&patientinfo).Error
40 43
 	rows, err := readUserDb.Offset(offset).Limit(limit).Raw("select Count(1) from sgj_users.sgj_user_org as u join sgj_xt.xt_receive_treatment_asses as x on x.user_org_id = u.id  where x.created_time >= ? AND x.created_time <= ?", to, ctime).Rows()
44
+	defer rows.Close()
45
+
41 46
 	if rows.Next() {
42 47
 		rows.Scan(&total)
43 48
 	}
@@ -50,6 +55,8 @@ func GetTodayBeforDislysisInfo(to int64, ctime int64, page int64, limit int64) (
50 55
 	offset := (page - 1) * limit
51 56
 	err = readUserDb.Raw("select * from sgj_users.sgj_user_org as u left join sgj_org_follow as f On f.org_id = u.id left JoIN sgj_admin as a On a.id = f.admin_user_id left join sgj_xt.xt_assessment_before_dislysis as x on x.user_org_id = u.id left JOIN sgj_xt.xt_patients as p On p.id = x.patient_id  where x.created_time >= ? AND x.created_time <= ? GROUP BY x.user_org_id", to, ctime).Scan(&patientinfo).Error
52 57
 	rows, err := readUserDb.Offset(offset).Limit(limit).Raw("select Count(1) from sgj_users.sgj_user_org as u join sgj_xt.xt_assessment_before_dislysis as x on x.user_org_id = u.id  where x.created_time >= ? AND x.created_time <= ?", to, ctime).Rows()
58
+	defer rows.Close()
59
+
53 60
 	if rows.Next() {
54 61
 		rows.Scan(&total)
55 62
 	}
@@ -63,6 +70,8 @@ func GetTodayDoctorsOrderInfo(to int64, ctime int64, page int64, limit int64) (p
63 70
 	offset := (page - 1) * limit
64 71
 	err = readUserDb.Raw("select * from sgj_users.sgj_user_org as u left join sgj_org_follow as f On f.org_id = u.id left JoIN sgj_admin as a On a.id = f.admin_user_id join sgj_xt.xt_doctor_advice as x on x.user_org_id = u.id left JOIN sgj_xt.xt_patients as p On p.id = x.patient_id  where x.created_time >= ? AND x.created_time <= ? GROUP BY x.user_org_id", to, ctime).Scan(&patientinfo).Error
65 72
 	rows, err := readUserDb.Offset(offset).Limit(limit).Raw("select Count(1) from sgj_users.sgj_user_org as u join sgj_xt.xt_doctor_advice as x on x.user_org_id = u.id  where x.created_time >= ? AND x.created_time <= ?", to, ctime).Rows()
73
+	defer rows.Close()
74
+
66 75
 	if rows.Next() {
67 76
 		rows.Scan(&total)
68 77
 	}
@@ -76,6 +85,8 @@ func GetTodayDoubleCheckInfo(to int64, ctime int64, page int64, limit int64) (pa
76 85
 	offset := (page - 1) * limit
77 86
 	err = readUserDb.Raw("select * from sgj_users.sgj_user_org as u left join sgj_org_follow as f On f.org_id = u.id left JoIN sgj_admin as a On a.id = f.admin_user_id join sgj_xt.xt_double_check as x on x.user_org_id = u.id left JOIN sgj_xt.xt_patients as p On p.id = x.patient_id  where x.created_time >= ? AND x.created_time <= ? GROUP BY x.user_org_id", to, ctime).Scan(&patientinfo).Error
78 87
 	rows, err := readUserDb.Offset(offset).Limit(limit).Raw("select Count(1) from sgj_users.sgj_user_org as u join sgj_xt.xt_double_check as x on x.user_org_id = u.id  where x.created_time >= ? AND x.created_time <= ?", to, ctime).Rows()
88
+	defer rows.Close()
89
+
79 90
 	if rows.Next() {
80 91
 		rows.Scan(&total)
81 92
 	}
@@ -89,6 +100,8 @@ func GetTodayDialysisMachinek(to int64, ctime int64, page int64, limit int64) (p
89 100
 	offset := (page - 1) * limit
90 101
 	err = readUserDb.Raw("select * from sgj_users.sgj_user_org as u left join sgj_org_follow as f On f.org_id = u.id left JoIN sgj_admin as a On a.id = f.admin_user_id left join sgj_xt.xt_dialysis_order as x on x.user_org_id = u.id left JOIN sgj_xt.xt_patients as p On p.id = x.patient_id  where x.created_time >= ? AND x.created_time <= ? GROUP BY x.user_org_id", to, ctime).Scan(&patientinfo).Error
91 102
 	rows, err := readUserDb.Offset(offset).Limit(limit).Raw("select Count(1) from sgj_users.sgj_user_org as u join sgj_xt.xt_dialysis_order as x on x.user_org_id = u.id  where x.created_time >= ? AND x.created_time <= ?", to, ctime).Rows()
103
+	defer rows.Close()
104
+
92 105
 	if rows.Next() {
93 106
 		rows.Scan(&total)
94 107
 	}
@@ -102,6 +115,8 @@ func GetTodayDialysisExamination(to int64, ctime int64, page int64, limit int64)
102 115
 	offset := (page - 1) * limit
103 116
 	err = readUserDb.Raw("select * from sgj_users.sgj_user_org as u left join sgj_org_follow as f On f.org_id = u.id left JoIN sgj_admin as a On a.id = f.admin_user_id join sgj_xt.xt_monitoring_record as x on x.user_org_id = u.id left JOIN sgj_xt.xt_patients as p On p.id = x.patient_id  where x.created_time >= ? AND x.created_time <= ? GROUP BY x.user_org_id", to, ctime).Scan(&patientinfo).Error
104 117
 	rows, err := readUserDb.Offset(offset).Limit(limit).Raw("select Count(1) from sgj_users.sgj_user_org as u join sgj_xt.xt_monitoring_record as x on x.user_org_id = u.id  where x.created_time >= ? AND x.created_time <= ?", to, ctime).Rows()
118
+	defer rows.Close()
119
+
105 120
 	if rows.Next() {
106 121
 		rows.Scan(&total)
107 122
 	}
@@ -115,6 +130,8 @@ func GetTodayBeforOrpenetration(to int64, ctime int64, page int64, limit int64)
115 130
 	offset := (page - 1) * limit
116 131
 	err = readUserDb.Raw("select * from sgj_users.sgj_user_org as u left join sgj_org_follow as f On f.org_id = u.id left JoIN sgj_admin as a On a.id = f.admin_user_id join sgj_xt.xt_dialysis_order as x on x.user_org_id = u.id left JOIN sgj_xt.xt_patients as p On p.id = x.patient_id  where x.created_time >= ? AND x.created_time <= ? GROUP BY x.user_org_id", to, ctime).Scan(&patientinfo).Error
117 132
 	rows, err := readUserDb.Offset(offset).Limit(limit).Raw("select Count(1) from sgj_users.sgj_user_org as u join sgj_xt.xt_dialysis_order as x on x.user_org_id = u.id  where x.created_time >= ? AND x.created_time <= ?", to, ctime).Rows()
133
+	defer rows.Close()
134
+
118 135
 	if rows.Next() {
119 136
 		rows.Scan(&total)
120 137
 	}
@@ -127,6 +144,8 @@ func GetTodayPostAssessment(to int64, ctime int64, page int64, limit int64) (pat
127 144
 	offset := (page - 1) * limit
128 145
 	err = readUserDb.Raw("select * from sgj_users.sgj_user_org as u left join sgj_org_follow as f On f.org_id = u.id left JoIN sgj_admin as a On a.id = f.admin_user_id join sgj_xt.xt_assessment_after_dislysis as x on x.user_org_id = u.id left JOIN sgj_xt.xt_patients as p On p.id = x.patient_id  where x.created_time >= ? AND x.created_time <= ? GROUP BY x.user_org_id", to, ctime).Scan(&patientinfo).Error
129 146
 	rows, err := readUserDb.Offset(offset).Limit(limit).Raw("select Count(1) from sgj_users.sgj_user_org as u join sgj_xt.xt_assessment_after_dislysis as x on x.user_org_id = u.id  where x.created_time >= ? AND x.created_time <= ?", to, ctime).Rows()
147
+	defer rows.Close()
148
+
130 149
 	if rows.Next() {
131 150
 		rows.Scan(&total)
132 151
 	}
@@ -138,6 +157,8 @@ func GetTodayEntrylist(to int64, ctime int64, limit int64, page int64) (patienti
138 157
 	offset := (page - 1) * limit
139 158
 	err = readUserDb.Raw("select * from sgj_users.sgj_user_org as u  join sgj_xt.xt_warehouse as x on x.org_id = u.id  LEFT JOIN  sgj_users.sgj_org_follow as f ON f.org_id = u.id  LEFT JOIN   sgj_users.sgj_admin as a on a.id = f.admin_user_id  where x.ctime >= ? AND x.ctime<= ? GROUP BY x.org_id", to, ctime).Scan(&patientinfo).Error
140 159
 	rows, err := readUserDb.Offset(offset).Limit(limit).Raw("select Count(1) from sgj_users.sgj_user_org as u join sgj_xt.xt_warehouse as x on x.org_id = u.id where x.ctime >= ? AND x.ctime <= ?", to, ctime).Rows()
160
+	defer rows.Close()
161
+
141 162
 	if rows.Next() {
142 163
 		rows.Scan(&total)
143 164
 	}
@@ -149,6 +170,8 @@ func GetTodayExitlist(to int64, ctime int64, limit int64, page int64) (patientin
149 170
 	offset := (page - 1) * limit
150 171
 	err = readUserDb.Raw("select * from sgj_users.sgj_user_org as u  join sgj_xt.xt_warehouse_out as x on x.org_id = u.id  LEFT JOIN  sgj_users.sgj_org_follow as f ON f.org_id = u.id  LEFT JOIN   sgj_users.sgj_admin as a on a.id = f.admin_user_id  where x.ctime >= ? AND x.ctime<= ? GROUP BY x.org_id", to, ctime).Scan(&patientinfo).Error
151 172
 	rows, err := readUserDb.Offset(offset).Limit(limit).Raw("select Count(1) from sgj_users.sgj_user_org as u join sgj_xt.xt_warehouse_out as x on x.org_id = u.id where x.ctime >= ? AND x.ctime <= ?", to, ctime).Rows()
173
+	defer rows.Close()
174
+
152 175
 	if rows.Next() {
153 176
 		rows.Scan(&total)
154 177
 	}

+ 37 - 58
service/org_service.go Parādīt failu

@@ -9,7 +9,10 @@ import (
9 9
 	"time"
10 10
 )
11 11
 
12
-func GetAllOrgList(active_status int64, depth_active_status int64, start_time int64, end_time int64, province int64, city int64, district int64, follow int64, keyword string, page int64, limit int64) (list []*models.Org, err error, total int64) {
12
+func GetAllOrgList(active_status int64, depth_active_status int64, start_time int64, end_time int64, province int64, city int64, district int64, follow int64, keyword string, page int64, limit int64, is_super_admin int64) (list []*models.Org, err error, total int64) {
13
+	fmt.Println("--------- ")
14
+
15
+	fmt.Println(follow)
13 16
 	offset := (page - 1) * limit
14 17
 	fmt.Println(offset)
15 18
 	db := readUserDb.Model(&models.Org{})
@@ -80,11 +83,19 @@ func GetAllOrgList(active_status int64, depth_active_status int64, start_time in
80 83
 		}
81 84
 
82 85
 	}
83
-	err = db.Where("sgj_user_org.status = 1 AND sgj_user_org.import <> 1").Preload("OrgFollow", func(db *gorm.DB) *gorm.DB {
86
+	if is_super_admin == 1 {
87
+		db = db.Where("sgj_user_org.status = 1 AND sgj_user_org.import <> 1").Group("sgj_user_org.id")
88
+
89
+	} else {
90
+		db = db.Where("sgj_user_org.status = 1 AND sgj_user_org.import <> 1 AND DATE_SUB(CURDATE(), INTERVAL 15 DAY) <= date(from_unixtime(sgj_user_org.ctime))").Group("sgj_user_org.id")
91
+	}
92
+
93
+	db = db.Count(&total)
94
+	err = db.Preload("OrgFollow", func(db *gorm.DB) *gorm.DB {
84 95
 		return db.Model(&models.OrgFollow{}).Where("status = 1").Preload("AdminAccount", "status = 1")
85 96
 	}).Preload("AdminUserLoginLog", func(db *gorm.DB) *gorm.DB {
86 97
 		return db.Model(&models.AdminUserLoginLog{}).Where("id = (SELECT max(id))")
87
-	}).Count(&total).Offset(offset).Limit(limit).Group("id").Find(&list).Error
98
+	}).Preload("Citys").Offset(offset).Limit(limit).Order("sgj_user_org.ctime DESC").Find(&list).Error
88 99
 	return
89 100
 }
90 101
 
@@ -112,6 +123,7 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64, to int64
112 123
 	switch statices_type {
113 124
 	case 1: //病人管理
114 125
 		rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_patients WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1", org_id, from, to).Rows()
126
+		defer rows.Close()
115 127
 		if err != nil {
116 128
 			return 0, err
117 129
 		}
@@ -121,6 +133,8 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64, to int64
121 133
 		break
122 134
 	case 2: //透析处方
123 135
 		rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_dialysis_prescription WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1", org_id, from, to).Rows()
136
+		defer rows.Close()
137
+
124 138
 		if err != nil {
125 139
 			return 0, err
126 140
 		}
@@ -130,6 +144,8 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64, to int64
130 144
 		break
131 145
 	case 3: //接诊评估
132 146
 		rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_receive_treatment_asses WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1", org_id, from, to).Rows()
147
+		defer rows.Close()
148
+
133 149
 		if err != nil {
134 150
 			return 0, err
135 151
 		}
@@ -139,6 +155,8 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64, to int64
139 155
 		break
140 156
 	case 4: //透前评估
141 157
 		rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_assessment_before_dislysis WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1", org_id, from, to).Rows()
158
+		defer rows.Close()
159
+
142 160
 		if err != nil {
143 161
 			return 0, err
144 162
 		}
@@ -148,6 +166,8 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64, to int64
148 166
 		break
149 167
 	case 5: //临时医嘱
150 168
 		rows, err := readDb.Raw("SELECT COUNT(DISTINCT patient_id) AS count FROM xt_doctor_advice WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1", org_id, from, to).Rows()
169
+		defer rows.Close()
170
+
151 171
 		if err != nil {
152 172
 			return 0, err
153 173
 		}
@@ -157,6 +177,8 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64, to int64
157 177
 		break
158 178
 	case 6: //双人核对
159 179
 		rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_double_check WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1", org_id, from, to).Rows()
180
+		defer rows.Close()
181
+
160 182
 		if err != nil {
161 183
 			return 0, err
162 184
 		}
@@ -166,6 +188,8 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64, to int64
166 188
 		break
167 189
 	case 7: //透析上机
168 190
 		rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_dialysis_order WHERE user_org_id = ? AND created_time >= ? AND created_time <= ?  AND status = 1 AND (stage = 2 OR stage = 1)", org_id, from, to).Rows()
191
+		defer rows.Close()
192
+
169 193
 		if err != nil {
170 194
 			return 0, err
171 195
 		}
@@ -176,6 +200,8 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64, to int64
176 200
 
177 201
 	case 8: //透析监测
178 202
 		rows, err := readDb.Raw("SELECT COUNT(DISTINCT patient_id) AS count FROM xt_monitoring_record WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1", org_id, from, to).Rows()
203
+		defer rows.Close()
204
+
179 205
 		if err != nil {
180 206
 			return 0, err
181 207
 		}
@@ -185,6 +211,8 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64, to int64
185 211
 		break
186 212
 	case 9: //透析下机
187 213
 		rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_dialysis_order WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND  stage = 2  AND status = 1", org_id, from, to).Rows()
214
+		defer rows.Close()
215
+
188 216
 		if err != nil {
189 217
 			return 0, err
190 218
 		}
@@ -194,6 +222,8 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64, to int64
194 222
 		break
195 223
 	case 10: //透后评估
196 224
 		rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_assessment_after_dislysis WHERE user_org_id = ? AND created_time >= ? AND created_time <= ? AND status = 1", org_id, from, to).Rows()
225
+		defer rows.Close()
226
+
197 227
 		if err != nil {
198 228
 			return 0, err
199 229
 		}
@@ -203,6 +233,8 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64, to int64
203 233
 		break
204 234
 	case 11: //入库单
205 235
 		rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_warehouse WHERE org_id = ? AND ctime >= ? AND mtime <= ? AND status = 1", org_id, from, to).Rows()
236
+		defer rows.Close()
237
+
206 238
 		if err != nil {
207 239
 			return 0, err
208 240
 		}
@@ -212,6 +244,8 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64, to int64
212 244
 		break
213 245
 	case 12: //出库单
214 246
 		rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_warehouse_out WHERE org_id = ? AND ctime >= ? AND mtime <= ? AND status = 1", org_id, from, to).Rows()
247
+		defer rows.Close()
248
+
215 249
 		if err != nil {
216 250
 			return 0, err
217 251
 		}
@@ -574,25 +608,6 @@ func GetRoles(orgID int64, appID int64, page int, count int) ([]*models.Role, in
574 608
 	return roles, totalCount, nil
575 609
 }
576 610
 
577
-func GetAdminUser(orgID int64, page int, count int) ([]*models.AdminUser, int, error) {
578
-	var roles []*models.AdminUser
579
-	var totalCount int
580
-	err := readUserDb.Model(&models.AdminUser{}).
581
-		Where("org_id = ? ", orgID).
582
-		Count(&totalCount).
583
-		Order("ctime asc").Limit(count).Offset((page - 1) * count).
584
-		Find(&roles).
585
-		Error
586
-	if err != nil {
587
-		if err == gorm.ErrRecordNotFound {
588
-			return make([]*models.AdminUser, 0), 0, nil
589
-		} else {
590
-			return nil, 0, err
591
-		}
592
-	}
593
-	return roles, totalCount, nil
594
-}
595
-
596 611
 type AdminUserManageViewModel struct {
597 612
 	AdminUserId int    `gorm:"admin_user_id" json:"user_id"`
598 613
 	UserName    string `gorm:"user_name" json:"user_name"`
@@ -629,12 +644,6 @@ func GetAdminUsersAndLoginInfo(orgID int64, appID int64, page int64, count int64
629 644
 		readUserDb.ScanRows(rows, &viewModel)
630 645
 		title, _ := models.UserTitle[viewModel.UserTitle]
631 646
 		viewModel.TitleName = title
632
-		// if viewModel.Ctime == 0 {
633
-		// 	viewModel.LastLoginTimeStr = ""
634
-		// } else {
635
-		// 	loginTime := time.Unix(viewModel.Ctime, 0)
636
-		// 	viewModel.LastLoginTimeStr = loginTime.Format("2006-01-02 15:04")
637
-		// }
638 647
 		viewModels = append(viewModels, &viewModel)
639 648
 	}
640 649
 	total := 0
@@ -680,33 +689,3 @@ func GetAllValidDeviceNumbers(orgID int64) ([]*DeviceNumberViewModel, error) {
680 689
 	}
681 690
 	return vms, nil
682 691
 }
683
-
684
-//func GetSpecialAdminUser(org_id int64, app_id int64,  page int64, count int64) ([]*AdminUserManageViewModel, error){
685
-//
686
-//	if count <= 0 {
687
-//		return []*AdminUserManageViewModel{}, nil
688
-//	}
689
-//	if page < 1 {
690
-//		page = 1
691
-//	}
692
-//	var viewModels []*AdminUserManageViewModel = make([]*AdminUserManageViewModel, 0)
693
-//	rows, err := readUserDb.Raw("SELECT u_a_r.admin_user_id, u_a_r.user_name, u_r.role_name, u_a_r.user_title, u_l.ip, u_l.ctime, u_a_r.status FROM sgj_user_admin_role AS u_a_r INNER JOIN sgj_user_role AS u_r ON u_a_r.org_id = u_r.org_id AND u_a_r.app_id = u_r.app_id AND u_r.id = u_a_r.role_id LEFT JOIN (SELECT * FROM (SELECT admin_user_id, org_id, app_id, ip, ctime FROM sgj_user_admin_login_log WHERE org_id = ? AND app_id = ? ORDER BY ctime DESC) AS t GROUP BY admin_user_id) AS u_l ON u_a_r.org_id = u_l.org_id AND u_a_r.app_id = u_l.app_id AND u_a_r.admin_user_id = u_l.admin_user_id INNER JOIN sgj_xt.xt_admin_user_special_permission AS xt_p ON  u_a_r.org_id = xt_p.org_id AND u_a_r.app_id = xt_p.app_id AND u_a_r.admin_user_id = xt_p.admin_user_id   WHERE u_a_r.org_id = ? AND u_a_r.app_id = ? GROUP BY u_a_r.admin_user_id LIMIT ? OFFSET ?;", orgID, appID, orgID, appID, count, (page-1)*count).Rows()
694
-//	defer rows.Close()
695
-//	if err != nil {
696
-//		if err == gorm.ErrRecordNotFound {
697
-//			return viewModels, nil
698
-//		} else {
699
-//			return nil, err
700
-//		}
701
-//	}
702
-//	for rows.Next() {
703
-//		var viewModel AdminUserManageViewModel
704
-//		readUserDb.ScanRows(rows, &viewModel)
705
-//		title, _ := models.UserTitle[viewModel.UserTitle]
706
-//		viewModel.TitleName = title
707
-//		viewModels = append(viewModels, &viewModel)
708
-//	}
709
-//	return viewModels, nil
710
-//
711
-//
712
-//}