浏览代码

机构功能相关接口

csx 5 年前
父节点
当前提交
b6f76e2b42

+ 4 - 0
controllers/admin_api_controllers/analysis_api_controller.go 查看文件

@@ -509,6 +509,10 @@ func (this *AnalysisAPIController) HomeStatistics() {
509 509
 		break
510 510
 
511 511
 	case 2:
512
+		orgRegisterStatistics, _ = service.GetYesterDayRegistedOrgCount()
513
+		newPatientStatistics, _ = service.GetYesterDayNewPatientCount()
514
+		orgActiveAdminStatistics, _ = service.GetYesterDayActiveAdminUserCount()
515
+		orgActiveStatistics, _ = service.GetYesterDayActiveOrgCount()
512 516
 
513 517
 		break
514 518
 	case 3:

+ 4 - 15
controllers/admin_api_controllers/org_api_controller.go 查看文件

@@ -29,7 +29,7 @@ func (this *OrgAPIController) GetOrgList() {
29 29
 		page = 1
30 30
 	}
31 31
 	if limit <= 0 {
32
-		limit = 7
32
+		limit = 10
33 33
 	}
34 34
 
35 35
 	timeLayout := "2006-01-02"
@@ -124,25 +124,14 @@ func (this *OrgAPIController) GetOrgDialysisOrderStatistics() {
124 124
 		}
125 125
 		break
126 126
 	case 2: //昨天
127
-		if len(range_data) > 0 {
128
-			rangeDate, parseDateErr = utils.ParseTimeStringToTime("2006-01-02", range_data)
129
-			if parseDateErr != nil {
130
-				this.ErrorLog("日期(%v)解析错误:%v", range_data, parseDateErr)
131
-				return
132
-			}
133
-			rangeTimeStamp = rangeDate.Unix()
134
-		} else {
135
-			rangeTimeStamp = 0
136
-		}
137
-		now := time.Now().Unix()
138
-		count, err := service.GetOrgDialysisCount(statistics_type, org_id, rangeTimeStamp, now)
127
+		var err error
128
+		orgDialysisOrderStatistics, err = service.GetYesterDayOrgDialysisCount(statistics_type, org_id)
139 129
 		if err != nil {
140 130
 			this.ErrorLog("错误:%v", err)
141 131
 			return
142
-
143 132
 		} else {
144 133
 			this.ServeSuccessJSON(map[string]interface{}{
145
-				"count": count,
134
+				"list": orgDialysisOrderStatistics,
146 135
 			})
147 136
 		}
148 137
 		break

+ 1 - 1
models/org_models.go 查看文件

@@ -29,7 +29,7 @@ type Org struct {
29 29
 	ContactName       string            `gorm:"column:contact_name" json:"contact_name"`
30 30
 	OrgGallery        []*OrgGallery     `gorm:"ForeignKey:OrgId" json:"org_gallery"`
31 31
 	AdminUserLoginLog AdminUserLoginLog `gorm:"ForeignKey:OrgId" json:"log"`
32
-	AdminUser         AdminUser         `gorm:"ForeignKey:Id" json:"admin"`
32
+	AdminUser         AdminUser         `gorm:"ForeignKey:Id;AssociationForeignKey:Creator" json:"admin"`
33 33
 	OrgFollow         []*OrgFollow      `gorm:"ForeignKey:OrgId" json:"follow"`
34 34
 }
35 35
 

+ 40 - 144
service/admin_service.go 查看文件

@@ -28,7 +28,7 @@ func GetAdminAccount(account string, password string) (*admin_models.AdminAccoun
28 28
 // 获取总机构数
29 29
 func GetTotalOrgCount() (int, error) {
30 30
 	var count int
31
-	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
32 32
 	if err != nil {
33 33
 		return 0, err
34 34
 	}
@@ -413,7 +413,7 @@ func GetAdminUserTotalCount() (int64, error) {
413 413
 func GetRegistedOrgCount(from int64, to int64) (int64, error) {
414 414
 
415 415
 	var count int64
416
-	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
417 417
 	if err != nil {
418 418
 		return 0, err
419 419
 	}
@@ -446,9 +446,34 @@ func GetActiveOrgTotalCount() (int64, error) {
446 446
 	return count, nil
447 447
 }
448 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
+
449 474
 //获取近七天每天的注册机构总量
450 475
 func GetWeekRegistedOrgCount() (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 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
452 477
 	return
453 478
 }
454 479
 
@@ -476,35 +501,9 @@ func GetWeekNewPatientCount() (weekStatistics []*admin_models.Statistics, err er
476 501
 	return
477 502
 }
478 503
 
479
-//获取近七天每天的注册机构总量
480
-func GetWeekRegistedOrgTotalCount() (int64, error) {
481
-	var result admin_models.Count
482
-	var err error
483
-	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
484
-	return result.Count, err
485
-}
486
-
487
-//获取近七天每天的机构活跃账号总量
488
-func GetWeekActiveAdminUserTotalCount() (int64, error) {
489
-	var result admin_models.Count
490
-	var err error
491
-	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
492
-	return result.Count, err
493
-
494
-}
495
-
496
-//获取近七天新增病人总量
497
-func GetWeekPatientTotalCount() (int64, error) {
498
-	var result admin_models.Count
499
-	var err error
500
-	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
501
-	return result.Count, err
502
-
503
-}
504
-
505 504
 //获取近30天每天的注册机构总量
506 505
 func GetMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
507
-	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
508 507
 	return
509 508
 }
510 509
 
@@ -526,33 +525,9 @@ func GetMonthNewPatientCount() (weekStatistics []*admin_models.Statistics, err e
526 525
 	return
527 526
 }
528 527
 
529
-//获取近30天每天的注册机构总量
530
-func GetMonthRegistedOrgTotalCount() (int64, error) {
531
-	var result admin_models.Count
532
-	var err error
533
-	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
534
-	return result.Count, err
535
-}
536
-
537
-//获取近30天每天的机构活跃账号总量
538
-func GetMonthActiveAdminUserTotalCount() (int64, error) {
539
-	var result admin_models.Count
540
-	var err error
541
-	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
542
-	return result.Count, err
543
-}
544
-
545
-//获取近30天每天的机构新增病人总量
546
-func GetMonthNewPatientTotalCount() (int64, error) {
547
-	var result admin_models.Count
548
-	var err error
549
-	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
550
-	return result.Count, err
551
-}
552
-
553 528
 //获取近3个月每个月的注册机构总量
554 529
 func GetThreeMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
555
-	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
556 531
 	return
557 532
 }
558 533
 
@@ -574,36 +549,9 @@ func GetThreeMonthNewPatientCount() (weekStatistics []*admin_models.Statistics,
574 549
 	return
575 550
 }
576 551
 
577
-//获取近3个月每个月的注册机构总量
578
-func GetThreeMonthRegistedOrgTotalCount() (int64, error) {
579
-	var result admin_models.Count
580
-	var err error
581
-	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
582
-	return result.Count, err
583
-
584
-}
585
-
586
-//获取近3个月每个月的机构活跃账号总量
587
-func GetThreeMonthActiveAdminUserTotalCount() (int64, error) {
588
-	var result admin_models.Count
589
-	var err error
590
-	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
591
-	return result.Count, err
592
-
593
-}
594
-
595
-//获取近3个月每个月机构新增病人总量
596
-func GetThreeMonthNewPatientTotalCount() (int64, error) {
597
-	var result admin_models.Count
598
-	var err error
599
-	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
600
-	return result.Count, err
601
-
602
-}
603
-
604 552
 //获取近半年每个月的注册机构总量
605 553
 func GetSixMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
606
-	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
607 555
 	return
608 556
 }
609 557
 
@@ -625,35 +573,9 @@ func GetSixMonthNewPatientCount() (weekStatistics []*admin_models.Statistics, er
625 573
 	return
626 574
 }
627 575
 
628
-//获取近半年每个月的注册机构总量
629
-func GetSixMonthRegistedOrgTotalCount() (int64, error) {
630
-	var result admin_models.Count
631
-	var err error
632
-	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
633
-	return result.Count, err
634
-}
635
-
636
-//获取近半年每个月的机构活跃账号总量
637
-func GetSixMonthActiveAdminUserTotalCount() (int64, error) {
638
-	var result admin_models.Count
639
-	var err error
640
-	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
641
-	return result.Count, err
642
-
643
-}
644
-
645
-//获取近半年每个月机构新增病人总量
646
-func GetSixMonthNewPatientTotalCount() (int64, error) {
647
-	var result admin_models.Count
648
-	var err error
649
-	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
650
-	return result.Count, err
651
-
652
-}
653
-
654 576
 //获取近1年每个月的注册机构总量
655 577
 func GetYearRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
656
-	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
657 579
 	return
658 580
 }
659 581
 
@@ -675,32 +597,6 @@ func GetYearNewPatientCount() (weekStatistics []*admin_models.Statistics, err er
675 597
 	return
676 598
 }
677 599
 
678
-//获取近1年每个月的注册机构总量
679
-func GetYearRegistedOrgTotalCount() (int64, error) {
680
-	var result admin_models.Count
681
-	var err error
682
-	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
683
-	return result.Count, err
684
-
685
-}
686
-
687
-//获取近1年每个月的机构活跃账号总量
688
-func GetYearActiveAdminUserTotalCount() (int64, error) {
689
-	var result admin_models.Count
690
-	var err error
691
-	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
692
-	return result.Count, err
693
-}
694
-
695
-//获取近1年每个月机构新增病人总量
696
-func GetYearNewPatientTotalCount() (int64, error) {
697
-	var result admin_models.Count
698
-	var err error
699
-	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
700
-	return result.Count, err
701
-
702
-}
703
-
704 600
 func GetAllAdmin() (admin []*admin_models.AdminAccount, err error) {
705 601
 	err = readUserDb.Model(&admin_models.AdminAccount{}).Where("is_super_admin <> 1 AND (status = 1 OR status = 2)").Find(&admin).Error
706 602
 	return
@@ -821,13 +717,13 @@ func GetAllWaitFollowOrgList(keyword string, page int64, limit int64, id int64)
821 717
 	db := readUserDb
822 718
 	if len(keyword) > 0 {
823 719
 		likeKey := "%" + keyword + "%"
824
-		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 (sgj_user_org.org_name Like ? OR sgj_user_org.org_short_name Like ?))", id, likeKey, likeKey).Count(&total).Offset(offset).Limit(limit).Scan(&orgViewModel).Error
825
-		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 (sgj_user_org.org_name Like ? OR sgj_user_org.org_short_name Like ?))  ", id, likeKey, likeKey).Scan(&totals)
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 (sgj_user_org.org_name Like ? OR sgj_user_org.org_short_name Like ?)) AND import <> 1", id, likeKey, likeKey).Count(&total).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 (sgj_user_org.org_name Like ? OR sgj_user_org.org_short_name Like ?))  AND import <> 1  ", id, likeKey, likeKey).Scan(&totals)
826 722
 
827 723
 	} else {
828
-		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)", id)
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)
829 725
 		err = db.Offset(offset).Limit(limit).Scan(&orgViewModel).Error
830
-		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)", id).Scan(&totals)
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)
831 727
 
832 728
 	}
833 729
 
@@ -847,8 +743,8 @@ func FindAllFollowOrg(keyword string, page int64, limit int64, admin_id int64) (
847 743
 		var rows *sql.Rows
848 744
 		var errs error
849 745
 		likeKey := "%" + keyword + "%"
850
-		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 ?) WHERE (follow.admin_user_id = ? AND follow.status = 1)", likeKey, likeKey, admin_id).Offset(offset).Limit(limit).Rows()
851
-		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 ?)  WHERE follow.admin_user_id = ? AND follow.status = 1", likeKey, likeKey, admin_id).Scan(&totals)
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)
852 748
 
853 749
 		defer rows.Close()
854 750
 		if errs != nil {
@@ -865,8 +761,8 @@ func FindAllFollowOrg(keyword string, page int64, limit int64, admin_id int64) (
865 761
 		var vms []*FollowViewModel = make([]*FollowViewModel, 0)
866 762
 		var rows *sql.Rows
867 763
 		var errs error
868
-		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  WHERE follow.admin_user_id = ? AND follow.status = 1", admin_id).Offset(offset).Limit(limit).Rows()
869
-		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  WHERE follow.admin_user_id = ? AND follow.status = 1", admin_id).Scan(&totals)
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)
870 766
 
871 767
 		defer rows.Close()
872 768
 		if errs != nil {

+ 65 - 14
service/org_service.go 查看文件

@@ -40,26 +40,22 @@ func GetAllOrgList(active_status int64, depth_active_status int64, start_time in
40 40
 		case 1:
41 41
 			now := time.Now()
42 42
 			zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
43
-			db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND sgj_user_admin_login_log.ctime >= ? AND sgj_user_admin_login_log.ctime <= ? AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ", zeroHourTimeOfToday.Unix(), now.Unix())
44
-			db = db.Joins("JOIN sgj_xt.xt_dialysis_order on sgj_xt.xt_dialysis_order.user_org_id = sgj_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') AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
43
+			db = db.Joins("JOIN sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = sgj_user_org.id AND sgj_xt.xt_dialysis_order.created_time >= ? AND sgj_xt.xt_dialysis_order.created_time <= ?", zeroHourTimeOfToday.Unix(), now.Unix())
45 44
 
46 45
 			break
47 46
 		case 2:
48
-			db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
49
-			db = db.Joins("JOIN sgj_xt.xt_dialysis_order on sgj_xt.xt_dialysis_order.user_org_id = sgj_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') AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
47
+			db = db.Joins("JOIN sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = sgj_user_org.id  AND DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_xt.xt_dialysis_order.created_time)) AND sgj_xt.xt_dialysis_order.status = 1")
50 48
 
51 49
 			break
52 50
 		case 3:
53
-			db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 1 MONTH) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
54
-			db = db.Joins("JOIN sgj_xt.xt_dialysis_order on sgj_xt.xt_dialysis_order.user_org_id = sgj_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') AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
51
+			db = db.Joins("JOIN sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = sgj_user_org.id  AND DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(sgj_xt.xt_dialysis_order.created_time)) AND sgj_xt.xt_dialysis_order.status = 1")
55 52
 
56 53
 			break
57 54
 		case 4:
58
-			db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 1 Year) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
59
-			db = db.Joins("JOIN sgj_xt.xt_dialysis_order on sgj_xt.xt_dialysis_order.user_org_id = sgj_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') AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
60
-
55
+			db = db.Joins("JOIN sgj_xt.xt_dialysis_order on sgj_xt.xt_dialysis_order.user_org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 1 Year) <= date(from_unixtime(sgj_xt.xt_dialysis_order.created_time)) AND sgj_xt.xt_dialysis_order.status = 1")
61 56
 			break
62 57
 		}
58
+
63 59
 		if province > 0 {
64 60
 			db = db.Where("sgj_user_org.province = ?", province)
65 61
 		}
@@ -84,7 +80,7 @@ func GetAllOrgList(active_status int64, depth_active_status int64, start_time in
84 80
 		}
85 81
 
86 82
 	}
87
-	err = db.Where("sgj_user_org.status = 1").Preload("OrgFollow", func(db *gorm.DB) *gorm.DB {
83
+	err = db.Where("sgj_user_org.status = 1 AND sgj_user_org.import <> 1").Preload("OrgFollow", func(db *gorm.DB) *gorm.DB {
88 84
 		return db.Model(&models.OrgFollow{}).Where("status = 1").Preload("AdminAccount", "status = 1")
89 85
 	}).Preload("AdminUserLoginLog", func(db *gorm.DB) *gorm.DB {
90 86
 		return db.Model(&models.AdminUserLoginLog{}).Where("id = (SELECT max(id))")
@@ -93,7 +89,7 @@ func GetAllOrgList(active_status int64, depth_active_status int64, start_time in
93 89
 }
94 90
 
95 91
 func GetOrgDetailInfo(org_id int64) (info models.Org, err error) {
96
-	err = readUserDb.Model(&models.Org{}).Where("id = ? AND status = 1", org_id).Preload("AdminUserLoginLog", func(db *gorm.DB) *gorm.DB {
92
+	err = readUserDb.Model(&models.Org{}).Where("id = ? AND status = 1 AND import <> 1", org_id).Preload("AdminUserLoginLog", func(db *gorm.DB) *gorm.DB {
97 93
 		return db.Model(&models.AdminUserLoginLog{}).Where("id = (SELECT max(id))")
98 94
 	}).Preload("AdminUser", "status = 1").Find(&info).Error
99 95
 	return
@@ -109,7 +105,7 @@ func GetAllOrgType() (types []*models.OrgType, err error) {
109 105
 	return
110 106
 }
111 107
 
112
-//设置今天和昨天的数据
108
+//设置今天
113 109
 func GetOrgDialysisCount(statices_type int64, org_id int64, from int64, to int64) (count int64, err error) {
114 110
 	var counts int64
115 111
 
@@ -227,6 +223,60 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64, to int64
227 223
 	return counts, nil
228 224
 }
229 225
 
226
+//获取昨天的数据
227
+func GetYesterDayOrgDialysisCount(statices_type int64, org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
228
+	fmt.Println(statices_type)
229
+
230
+	switch statices_type {
231
+	case 1: //病人管理
232
+		err = readDb.Raw("select count(distinct id) 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)) AND status = 1  AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
233
+
234
+		break
235
+	case 2: //透析处方
236
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times  from xt_dialysis_prescription  where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
237
+
238
+		break
239
+	case 3: //接诊评估
240
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times  from xt_receive_treatment_asses  where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
241
+
242
+		break
243
+	case 4: //透前评估
244
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times  from xt_assessment_before_dislysis  where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
245
+		break
246
+
247
+	case 5: //临时医嘱
248
+		err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times  from xt_doctor_advice  where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
249
+
250
+		break
251
+	case 6: //双人核对
252
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times  from xt_double_check  where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
253
+
254
+		break
255
+	case 7: //透析上机
256
+		err = readDb.Raw("select count(distinct 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  AND user_org_id = ? AND (stage = 2 OR stage = 1)  GROUP BY times", org_id).Scan(&weekStatistics).Error
257
+		break
258
+
259
+	case 8: //透析监测
260
+		err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times  from xt_monitoring_record  where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ?  GROUP BY times", org_id).Scan(&weekStatistics).Error
261
+		break
262
+	case 9: //透析下机
263
+		err = readDb.Raw("select count(distinct 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 stage = 2 AND status = 1  AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
264
+
265
+		break
266
+	case 10: //透后评估
267
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times  from xt_assessment_after_dislysis  where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(created_time)) AND status = 1  AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
268
+		break
269
+	case 11: //入库单
270
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times  from xt_warehouse  where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(ctime)) AND status = 1 AND org_id = ?  GROUP BY times", org_id).Scan(&weekStatistics).Error
271
+		break
272
+	case 12: //出库单
273
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times  from xt_warehouse_out  where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
274
+		break
275
+	}
276
+
277
+	return
278
+}
279
+
230 280
 //获取近七天的数据
231 281
 func GetWeekOrgDialysisCount(statices_type int64, org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
232 282
 	fmt.Println(statices_type)
@@ -549,8 +599,9 @@ type AdminUserManageViewModel struct {
549 599
 	RoleName    string `gorm:"role_name" json:"role_name"`
550 600
 	UserTitle   int    `gorm:"user_title" json:"user_title"`
551 601
 	Ip          string `gorm:"ip" json:"ip"`
552
-	Ctime       int64  `gorm:"ctime" json:"last_login_time"`
602
+	LastTime    int64  `gorm:"ctime" json:"last_login_time"`
553 603
 	Status      int    `gorm:"status" json:"status"`
604
+	Mobile      string `gorm:"mobile" json:"mobile"`
554 605
 
555 606
 	// LastLoginTimeStr string `gorm:"-" json:"last_login_time_formatted"`
556 607
 	TitleName string `gorm:"-" json:"title_name"`
@@ -564,7 +615,7 @@ func GetAdminUsersAndLoginInfo(orgID int64, appID int64, page int64, count int64
564 615
 		page = 1
565 616
 	}
566 617
 	var viewModels []*AdminUserManageViewModel = make([]*AdminUserManageViewModel, 0)
567
-	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 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()
618
+	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.last_time, u_a_r.status, admin.mobile FROM sgj_user_admin_role AS u_a_r JOIN sgj_user_admin AS admin ON admin.id = u_a_r.admin_user_id  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, MAX(ctime) as last_time FROM sgj_user_admin_login_log WHERE org_id = ? AND app_id = ? GROUP BY admin_user_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 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()
568 619
 	defer rows.Close()
569 620
 	if err != nil {
570 621
 		if err == gorm.ErrRecordNotFound {