|
@@ -5,6 +5,7 @@ package service
|
5
|
5
|
import (
|
6
|
6
|
"XT_Admin_Api/models"
|
7
|
7
|
"XT_Admin_Api/models/admin_models"
|
|
8
|
+ "database/sql"
|
8
|
9
|
"fmt"
|
9
|
10
|
"strings"
|
10
|
11
|
"time"
|
|
@@ -27,7 +28,7 @@ func GetAdminAccount(account string, password string) (*admin_models.AdminAccoun
|
27
|
28
|
// 获取总机构数
|
28
|
29
|
func GetTotalOrgCount() (int, error) {
|
29
|
30
|
var count int
|
30
|
|
- err := readUserDb.Model(&models.Org{}).Where("status <> 0").Count(&count).Error
|
|
31
|
+ err := readUserDb.Model(&models.Org{}).Where("status <> 0 AND import <> 1").Count(&count).Error
|
31
|
32
|
if err != nil {
|
32
|
33
|
return 0, err
|
33
|
34
|
}
|
|
@@ -412,7 +413,7 @@ func GetAdminUserTotalCount() (int64, error) {
|
412
|
413
|
func GetRegistedOrgCount(from int64, to int64) (int64, error) {
|
413
|
414
|
|
414
|
415
|
var count int64
|
415
|
|
- err := readUserDb.Model(&models.Org{}).Where("status <> 0 AND ctime >= ? AND ctime <= ?", from, to).Count(&count).Error
|
|
416
|
+ err := readUserDb.Model(&models.Org{}).Where("status <> 0 AND ctime >= ? AND ctime <= ? AND AND import <> 1", from, to).Count(&count).Error
|
416
|
417
|
if err != nil {
|
417
|
418
|
return 0, err
|
418
|
419
|
}
|
|
@@ -422,7 +423,7 @@ func GetRegistedOrgCount(from int64, to int64) (int64, error) {
|
422
|
423
|
// 获取一段时间内的活跃机构数
|
423
|
424
|
func GetActiveOrgCount(from int64, to int64) (int64, error) {
|
424
|
425
|
var count int64
|
425
|
|
- rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT org_id) AS count FROM sgj_user_admin_login_log JOIN sgj_xt.xt_dialysis_order ON sgj_user_admin_login_log.org_id = sgj_xt.xt_dialysis_order.user_org_id AND DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m-%d') = DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)),'%Y-%m-%d') where sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 AND sgj_user_admin_login_log.ctime >= ? AND sgj_user_admin_login_log.ctime <= ? ", from, to).Rows()
|
|
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()
|
426
|
427
|
if err != nil {
|
427
|
428
|
return 0, err
|
428
|
429
|
}
|
|
@@ -435,7 +436,7 @@ func GetActiveOrgCount(from int64, to int64) (int64, error) {
|
435
|
436
|
// 获取所有活跃机构数
|
436
|
437
|
func GetActiveOrgTotalCount() (int64, error) {
|
437
|
438
|
var count int64
|
438
|
|
- rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT org_id) AS count FROM sgj_user_admin_login_log JOIN sgj_xt.xt_dialysis_order ON sgj_user_admin_login_log.org_id = sgj_xt.xt_dialysis_order.user_org_id AND DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m-%d') = DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)),'%Y-%m-%d') where sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1").Rows()
|
|
439
|
+ rows, err := readDb.Raw("SELECT COUNT(DISTINCT user_org_id) AS count FROM sgj_xt.xt_dialysis_order Where status = 1").Rows()
|
439
|
440
|
if err != nil {
|
440
|
441
|
return 0, err
|
441
|
442
|
}
|
|
@@ -445,9 +446,34 @@ func GetActiveOrgTotalCount() (int64, error) {
|
445
|
446
|
return count, nil
|
446
|
447
|
}
|
447
|
448
|
|
|
449
|
+//获取昨天的注册机构总量
|
|
450
|
+func GetYesterDayRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
|
|
451
|
+ err = readUserDb.Raw("select count(id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from sgj_user_org where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(sgj_user_org.ctime)) AND sgj_user_org.status = 1 AND sgj_user_org.import <> 1 GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
|
|
452
|
+ return
|
|
453
|
+}
|
|
454
|
+
|
|
455
|
+//获取近昨天的的机构活跃总量
|
|
456
|
+func GetYesterDayActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
|
|
457
|
+ db := readDb.Raw("select count(DISTINCT(user_org_id)) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(created_time)) AND status = 1 GROUP BY date(from_unixtime(created_time));")
|
|
458
|
+ err = db.Scan(&weekStatistics).Error
|
|
459
|
+ return
|
|
460
|
+}
|
|
461
|
+
|
|
462
|
+//获取昨天的的机构活跃账号总量
|
|
463
|
+func GetYesterDayActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
|
|
464
|
+ err = readUserDb.Raw("select count(DISTINCT(admin_user_id)) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from sgj_user_admin_login_log where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(sgj_user_admin_login_log.ctime)) AND operate_type = 1 AND app_type = 3 GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
|
|
465
|
+ return
|
|
466
|
+}
|
|
467
|
+
|
|
468
|
+//获取昨天的的机构新增病人总量
|
|
469
|
+func GetYesterDayNewPatientCount() (weekStatistics []*admin_models.Statistics, err error) {
|
|
470
|
+ err = readDb.Raw("select count(DISTINCT(id_card_no)) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_patients where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(created_time)) GROUP BY date(from_unixtime(created_time));").Scan(&weekStatistics).Error
|
|
471
|
+ return
|
|
472
|
+}
|
|
473
|
+
|
448
|
474
|
//获取近七天每天的注册机构总量
|
449
|
475
|
func GetWeekRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
|
450
|
|
- err = readUserDb.Raw("select count(id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from sgj_user_org where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_org.ctime)) GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
|
|
476
|
+ err = readUserDb.Raw("select count(id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from sgj_user_org where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_org.ctime)) AND sgj_user_org.status = 1 AND sgj_user_org.import <> 1 GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
|
451
|
477
|
return
|
452
|
478
|
}
|
453
|
479
|
|
|
@@ -458,7 +484,7 @@ func GetWeekRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err e
|
458
|
484
|
|
459
|
485
|
//获取近七天每天的机构活跃总量
|
460
|
486
|
func GetWeekActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
|
461
|
|
- db := readUserDb.Raw("select count(DISTINCT(org_id)) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from sgj_user_admin_login_log join sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = sgj_user_admin_login_log.org_id AND DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m-%d') = DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m-%d') where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND operate_type = 1 AND app_type = 3 GROUP BY date(from_unixtime(ctime));")
|
|
487
|
+ db := readDb.Raw("select count(DISTINCT(user_org_id)) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 GROUP BY date(from_unixtime(created_time));")
|
462
|
488
|
err = db.Scan(&weekStatistics).Error
|
463
|
489
|
return
|
464
|
490
|
}
|
|
@@ -475,41 +501,15 @@ func GetWeekNewPatientCount() (weekStatistics []*admin_models.Statistics, err er
|
475
|
501
|
return
|
476
|
502
|
}
|
477
|
503
|
|
478
|
|
-//获取近七天每天的注册机构总量
|
479
|
|
-func GetWeekRegistedOrgTotalCount() (int64, error) {
|
480
|
|
- var result admin_models.Count
|
481
|
|
- var err error
|
482
|
|
- err = readUserDb.Raw("select count(id) as count from sgj_user_org where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_org.ctime))").Scan(&result).Error
|
483
|
|
- return result.Count, err
|
484
|
|
-}
|
485
|
|
-
|
486
|
|
-//获取近七天每天的机构活跃账号总量
|
487
|
|
-func GetWeekActiveAdminUserTotalCount() (int64, error) {
|
488
|
|
- var result admin_models.Count
|
489
|
|
- var err error
|
490
|
|
- err = readUserDb.Raw("select count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND operate_type = 1 ").Scan(&result).Error
|
491
|
|
- return result.Count, err
|
492
|
|
-
|
493
|
|
-}
|
494
|
|
-
|
495
|
|
-//获取近七天新增病人总量
|
496
|
|
-func GetWeekPatientTotalCount() (int64, error) {
|
497
|
|
- var result admin_models.Count
|
498
|
|
- var err error
|
499
|
|
- err = readDb.Raw("select count(DISTINCT(id_card_no)) as count from xt_patients where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time))").Scan(&result).Error
|
500
|
|
- return result.Count, err
|
501
|
|
-
|
502
|
|
-}
|
503
|
|
-
|
504
|
504
|
//获取近30天每天的注册机构总量
|
505
|
505
|
func GetMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
|
506
|
|
- err = readUserDb.Raw("select count(id) as count,DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from sgj_user_org where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(sgj_user_org.ctime)) GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
|
|
506
|
+ err = readUserDb.Raw("select count(id) as count,DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times from sgj_user_org where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(sgj_user_org.ctime)) AND sgj_user_org.status = 1 AND sgj_user_org.import <> 1 GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
|
507
|
507
|
return
|
508
|
508
|
}
|
509
|
509
|
|
510
|
510
|
//获取近30天每天的机构活跃总量
|
511
|
511
|
func GetMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
|
512
|
|
- err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times,count(DISTINCT(org_id)) as count From (select ctime,org_id FROM sgj_user_admin_login_log where app_type = 3 AND org_id > 0 ) T join sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = T.org_id AND DATE_FORMAT(date(from_unixtime(T.ctime)) ,'%Y-%m') =DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m') where DATE_FORMAT(date(from_unixtime(T.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 1 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
|
|
512
|
+ err = readDb.Raw("select count(DISTINCT(user_org_id)) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 GROUP BY date(from_unixtime(created_time));").Scan(&weekStatistics).Error
|
513
|
513
|
return
|
514
|
514
|
}
|
515
|
515
|
|
|
@@ -525,33 +525,9 @@ func GetMonthNewPatientCount() (weekStatistics []*admin_models.Statistics, err e
|
525
|
525
|
return
|
526
|
526
|
}
|
527
|
527
|
|
528
|
|
-//获取近30天每天的注册机构总量
|
529
|
|
-func GetMonthRegistedOrgTotalCount() (int64, error) {
|
530
|
|
- var result admin_models.Count
|
531
|
|
- var err error
|
532
|
|
- err = readUserDb.Raw("select count(id) as count from sgj_user_org where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(sgj_user_org.ctime))").Scan(&result).Error
|
533
|
|
- return result.Count, err
|
534
|
|
-}
|
535
|
|
-
|
536
|
|
-//获取近30天每天的机构活跃账号总量
|
537
|
|
-func GetMonthActiveAdminUserTotalCount() (int64, error) {
|
538
|
|
- var result admin_models.Count
|
539
|
|
- var err error
|
540
|
|
- err = readUserDb.Raw("select count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND operate_type = 1 ").Scan(&result).Error
|
541
|
|
- return result.Count, err
|
542
|
|
-}
|
543
|
|
-
|
544
|
|
-//获取近30天每天的机构新增病人总量
|
545
|
|
-func GetMonthNewPatientTotalCount() (int64, error) {
|
546
|
|
- var result admin_models.Count
|
547
|
|
- var err error
|
548
|
|
- err = readDb.Raw("select count(DISTINCT(id_card_no)) as count from xt_patients where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) ").Scan(&result).Error
|
549
|
|
- return result.Count, err
|
550
|
|
-}
|
551
|
|
-
|
552
|
528
|
//获取近3个月每个月的注册机构总量
|
553
|
529
|
func GetThreeMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
|
554
|
|
- err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
|
|
530
|
+ err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m') AND sgj_user_org.status = 1 AND sgj_user_org.import <> 1 group by times").Scan(&weekStatistics).Error
|
555
|
531
|
return
|
556
|
532
|
}
|
557
|
533
|
|
|
@@ -563,7 +539,7 @@ func GetThreeMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statist
|
563
|
539
|
|
564
|
540
|
//获取近3个月每个月的机构活跃总量
|
565
|
541
|
func GetThreeMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
|
566
|
|
- err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times,count(DISTINCT(org_id)) as count From (select ctime,org_id FROM sgj_user_admin_login_log where app_type = 3 AND org_id > 0 AND operate_type = 1 ) T join sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = T.org_id AND DATE_FORMAT(date(from_unixtime(T.ctime)) ,'%Y-%m') =DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m') where DATE_FORMAT(date(from_unixtime(T.ctime)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
|
|
542
|
+ err = readDb.Raw("select DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times,count(DISTINCT(user_org_id)) as count From xt_dialysis_order where DATE_FORMAT(date(from_unixtime(created_time)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m') AND status = 1 group by times").Scan(&weekStatistics).Error
|
567
|
543
|
return
|
568
|
544
|
}
|
569
|
545
|
|
|
@@ -573,36 +549,9 @@ func GetThreeMonthNewPatientCount() (weekStatistics []*admin_models.Statistics,
|
573
|
549
|
return
|
574
|
550
|
}
|
575
|
551
|
|
576
|
|
-//获取近3个月每个月的注册机构总量
|
577
|
|
-func GetThreeMonthRegistedOrgTotalCount() (int64, error) {
|
578
|
|
- var result admin_models.Count
|
579
|
|
- var err error
|
580
|
|
- err = readUserDb.Raw("select count(DISTINCT(id)) as count from sgj_user_org where DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m')").Scan(&result).Error
|
581
|
|
- return result.Count, err
|
582
|
|
-
|
583
|
|
-}
|
584
|
|
-
|
585
|
|
-//获取近3个月每个月的机构活跃账号总量
|
586
|
|
-func GetThreeMonthActiveAdminUserTotalCount() (int64, error) {
|
587
|
|
- var result admin_models.Count
|
588
|
|
- var err error
|
589
|
|
- err = readUserDb.Raw("select count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m') AND operate_type = 1 ").Scan(&result).Error
|
590
|
|
- return result.Count, err
|
591
|
|
-
|
592
|
|
-}
|
593
|
|
-
|
594
|
|
-//获取近3个月每个月机构新增病人总量
|
595
|
|
-func GetThreeMonthNewPatientTotalCount() (int64, error) {
|
596
|
|
- var result admin_models.Count
|
597
|
|
- var err error
|
598
|
|
- err = readDb.Raw("select count(DISTINCT(id_card_no)) as count from xt_patients where DATE_FORMAT(date(from_unixtime(xt_patients.created_time)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m')").Scan(&result).Error
|
599
|
|
- return result.Count, err
|
600
|
|
-
|
601
|
|
-}
|
602
|
|
-
|
603
|
552
|
//获取近半年每个月的注册机构总量
|
604
|
553
|
func GetSixMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
|
605
|
|
- err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
|
|
554
|
+ err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m') AND sgj_user_org.status = 1 AND sgj_user_org.import <> 1 group by times").Scan(&weekStatistics).Error
|
606
|
555
|
return
|
607
|
556
|
}
|
608
|
557
|
|
|
@@ -614,7 +563,7 @@ func GetSixMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statistic
|
614
|
563
|
|
615
|
564
|
//获取近半年每个月的机构活跃总量
|
616
|
565
|
func GetSixMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
|
617
|
|
- err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times,count(DISTINCT(org_id)) as count From (select ctime,org_id FROM sgj_user_admin_login_log where app_type = 3 AND org_id > 0 AND operate_type = 1 ) T join sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = T.org_id AND DATE_FORMAT(date(from_unixtime(T.ctime)) ,'%Y-%m') =DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m') where DATE_FORMAT(date(from_unixtime(T.ctime)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
|
|
566
|
+ err = readDb.Raw("select DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times,count(DISTINCT(user_org_id)) as count From xt_dialysis_order where DATE_FORMAT(date(from_unixtime(created_time)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m') AND status = 1 group by times").Scan(&weekStatistics).Error
|
618
|
567
|
return
|
619
|
568
|
}
|
620
|
569
|
|
|
@@ -624,35 +573,9 @@ func GetSixMonthNewPatientCount() (weekStatistics []*admin_models.Statistics, er
|
624
|
573
|
return
|
625
|
574
|
}
|
626
|
575
|
|
627
|
|
-//获取近半年每个月的注册机构总量
|
628
|
|
-func GetSixMonthRegistedOrgTotalCount() (int64, error) {
|
629
|
|
- var result admin_models.Count
|
630
|
|
- var err error
|
631
|
|
- err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m')").Scan(&result).Error
|
632
|
|
- return result.Count, err
|
633
|
|
-}
|
634
|
|
-
|
635
|
|
-//获取近半年每个月的机构活跃账号总量
|
636
|
|
-func GetSixMonthActiveAdminUserTotalCount() (int64, error) {
|
637
|
|
- var result admin_models.Count
|
638
|
|
- var err error
|
639
|
|
- err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m') as times,count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m')").Scan(&result).Error
|
640
|
|
- return result.Count, err
|
641
|
|
-
|
642
|
|
-}
|
643
|
|
-
|
644
|
|
-//获取近半年每个月机构新增病人总量
|
645
|
|
-func GetSixMonthNewPatientTotalCount() (int64, error) {
|
646
|
|
- var result admin_models.Count
|
647
|
|
- var err error
|
648
|
|
- err = readDb.Raw("select DATE_FORMAT(date(from_unixtime(xt_patients.created_time)) ,'%Y-%m') as times,count(DISTINCT(id_card_no)) as count from xt_patients where DATE_FORMAT(date(from_unixtime(xt_patients.created_time)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m')").Scan(&result).Error
|
649
|
|
- return result.Count, err
|
650
|
|
-
|
651
|
|
-}
|
652
|
|
-
|
653
|
576
|
//获取近1年每个月的注册机构总量
|
654
|
577
|
func GetYearRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
|
655
|
|
- err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
|
|
578
|
+ err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') AND sgj_user_org.status = 1 AND sgj_user_org.import <> 1 group by times").Scan(&weekStatistics).Error
|
656
|
579
|
return
|
657
|
580
|
}
|
658
|
581
|
|
|
@@ -664,7 +587,7 @@ func GetYearActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, e
|
664
|
587
|
|
665
|
588
|
//获取近1年每个月的机构活跃总量
|
666
|
589
|
func GetYearActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
|
667
|
|
- err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times,count(DISTINCT(org_id)) as count From (select ctime,org_id FROM sgj_user_admin_login_log where app_type = 3 AND org_id > 0 AND operate_type = 1 ) T join sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = T.org_id AND DATE_FORMAT(date(from_unixtime(T.ctime)) ,'%Y-%m') =DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m') where DATE_FORMAT(date(from_unixtime(T.ctime)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
|
|
590
|
+ err = readDb.Raw("select DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times,count(DISTINCT(user_org_id)) as count From xt_dialysis_order where DATE_FORMAT(date(from_unixtime(created_time)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') AND status = 1 group by times").Scan(&weekStatistics).Error
|
668
|
591
|
return
|
669
|
592
|
}
|
670
|
593
|
|
|
@@ -674,32 +597,6 @@ func GetYearNewPatientCount() (weekStatistics []*admin_models.Statistics, err er
|
674
|
597
|
return
|
675
|
598
|
}
|
676
|
599
|
|
677
|
|
-//获取近1年每个月的注册机构总量
|
678
|
|
-func GetYearRegistedOrgTotalCount() (int64, error) {
|
679
|
|
- var result admin_models.Count
|
680
|
|
- var err error
|
681
|
|
- err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m')").Scan(&result).Error
|
682
|
|
- return result.Count, err
|
683
|
|
-
|
684
|
|
-}
|
685
|
|
-
|
686
|
|
-//获取近1年每个月的机构活跃账号总量
|
687
|
|
-func GetYearActiveAdminUserTotalCount() (int64, error) {
|
688
|
|
- var result admin_models.Count
|
689
|
|
- var err error
|
690
|
|
- err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m') as times,count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m')").Scan(&result).Error
|
691
|
|
- return result.Count, err
|
692
|
|
-}
|
693
|
|
-
|
694
|
|
-//获取近1年每个月机构新增病人总量
|
695
|
|
-func GetYearNewPatientTotalCount() (int64, error) {
|
696
|
|
- var result admin_models.Count
|
697
|
|
- var err error
|
698
|
|
- err = readDb.Raw("select count(DISTINCT(id_card_no)) as count from xt_patients where DATE_FORMAT(date(from_unixtime(xt_patients.created_time)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') AND status > 0").Scan(&result).Error
|
699
|
|
- return result.Count, err
|
700
|
|
-
|
701
|
|
-}
|
702
|
|
-
|
703
|
600
|
func GetAllAdmin() (admin []*admin_models.AdminAccount, err error) {
|
704
|
601
|
err = readUserDb.Model(&admin_models.AdminAccount{}).Where("is_super_admin <> 1 AND (status = 1 OR status = 2)").Find(&admin).Error
|
705
|
602
|
return
|
|
@@ -810,3 +707,74 @@ func FindFollowInfoById(org_id int64, admin_user_id int64) (info models.OrgFollo
|
810
|
707
|
err = readUserDb.Model(&models.OrgFollow{}).Where("org_id = ? AND status = 1 AND admin_user_id = ?", org_id, admin_user_id).First(&info).Error
|
811
|
708
|
return
|
812
|
709
|
}
|
|
710
|
+
|
|
711
|
+func GetAllWaitFollowOrgList(keyword string, page int64, limit int64, id int64) (orgViewModel []*OrgViewModel, err error, total int64) {
|
|
712
|
+ type Total struct {
|
|
713
|
+ Count int64
|
|
714
|
+ }
|
|
715
|
+ var totals Total
|
|
716
|
+ offset := (page - 1) * limit
|
|
717
|
+ db := readUserDb
|
|
718
|
+ if len(keyword) > 0 {
|
|
719
|
+ 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)
|
|
722
|
+
|
|
723
|
+ } 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)
|
|
725
|
+ 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)
|
|
727
|
+
|
|
728
|
+ }
|
|
729
|
+
|
|
730
|
+ return orgViewModel, err, totals.Count
|
|
731
|
+}
|
|
732
|
+
|
|
733
|
+func FindAllFollowOrg(keyword string, page int64, limit int64, admin_id int64) (follow []*FollowViewModel, err error, total int64) {
|
|
734
|
+ type Total struct {
|
|
735
|
+ Count int64
|
|
736
|
+ }
|
|
737
|
+ var totals Total
|
|
738
|
+
|
|
739
|
+ offset := (page - 1) * limit
|
|
740
|
+
|
|
741
|
+ if len(keyword) > 0 {
|
|
742
|
+ var vms []*FollowViewModel = make([]*FollowViewModel, 0)
|
|
743
|
+ var rows *sql.Rows
|
|
744
|
+ var errs error
|
|
745
|
+ 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)
|
|
748
|
+
|
|
749
|
+ defer rows.Close()
|
|
750
|
+ if errs != nil {
|
|
751
|
+ return nil, errs, totals.Count
|
|
752
|
+ }
|
|
753
|
+ for rows.Next() {
|
|
754
|
+ var vm FollowViewModel
|
|
755
|
+ readDb.ScanRows(rows, &vm)
|
|
756
|
+ vms = append(vms, &vm)
|
|
757
|
+ }
|
|
758
|
+
|
|
759
|
+ return vms, nil, totals.Count
|
|
760
|
+ } else {
|
|
761
|
+ var vms []*FollowViewModel = make([]*FollowViewModel, 0)
|
|
762
|
+ var rows *sql.Rows
|
|
763
|
+ 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)
|
|
766
|
+
|
|
767
|
+ defer rows.Close()
|
|
768
|
+ if errs != nil {
|
|
769
|
+ return nil, errs, totals.Count
|
|
770
|
+ }
|
|
771
|
+ for rows.Next() {
|
|
772
|
+ var vm FollowViewModel
|
|
773
|
+ readDb.ScanRows(rows, &vm)
|
|
774
|
+ vms = append(vms, &vm)
|
|
775
|
+ }
|
|
776
|
+
|
|
777
|
+ return vms, nil, totals.Count
|
|
778
|
+ }
|
|
779
|
+
|
|
780
|
+}
|