Browse Source

修改接口

csx 5 years ago
parent
commit
542eb29c56

+ 3 - 3
controllers/admin_api_controllers/admin_api_router_register.go View File

@@ -15,9 +15,9 @@ func AdminAPIControllersRegisterRouters() {
15 15
 	beego.Router("/admin/api/patient/analysis", &AnalysisAPIController{}, "get:PatientAnalysis")
16 16
 	beego.Router("/admin/api/home/statistics", &AnalysisAPIController{}, "get:HomeStatistics")
17 17
 	beego.Router("/admin/api/getdistrictsbyupid", &OrgAPIController{}, "get:GetDistrictsByUpid")
18
+	beego.Router("/admin/api/org", &OrgAPIController{}, "get:GetOrgList")
18 19
 	beego.Router("/admin/api/org/initdata", &OrgAPIController{}, "get:GetInitData")
19
-
20
-
21
-
20
+	beego.Router("/admin/api/orginfo", &OrgAPIController{}, "get:GetOrgInfo")
21
+	beego.Router("/admin/api/org/statistics", &OrgAPIController{}, "get:GetOrgDialysisOrderStatistics")
22 22
 
23 23
 }

+ 190 - 70
controllers/admin_api_controllers/org_api_controller.go View File

@@ -1,7 +1,12 @@
1 1
 package admin_api_controllers
2 2
 
3 3
 import (
4
+	"XT_Admin_Api/enums"
5
+	"XT_Admin_Api/models/admin_models"
4 6
 	"XT_Admin_Api/service"
7
+	"XT_Admin_Api/utils"
8
+	"fmt"
9
+	"time"
5 10
 )
6 11
 
7 12
 type OrgAPIController struct {
@@ -9,96 +14,211 @@ type OrgAPIController struct {
9 14
 }
10 15
 
11 16
 func (this *OrgAPIController) GetOrgList() {
12
-	//active_status,_ := this.GetInt64("active_status")
13
-	//depth_active_status,_ := this.GetInt64("depth_active_status")
14
-	//start_time := this.GetString("start_time")
15
-	//end_time := this.GetString("end_time")
16
-	//province,_ := this.GetInt64("province")
17
-	//city,_ := this.GetInt64("city")
18
-	//district,_ := this.GetInt64("district")
19
-	//follow,_ := this.GetInt64("follow")
20
-	//keyword := this.GetString("keyword")
21
-	//page, _ := this.GetInt64("page", 0)
22
-	//limit, _ := this.GetInt64("limit", 0)
23
-	//
24
-	//if page <= 0 {
25
-	//	page = 1
26
-	//}
27
-	//if limit <= 0 {
28
-	//	limit = 10
29
-	//}
30
-	//adminInfo := this.GetAdminInfo()
31
-	//if adminInfo.Admin.IsSuperAdmin == 1 {
32
-	//	list, err, total := service.GetAllOrgList(active_status,depth_active_status,start_time,end_time,province,city,district,follow,keyword,page,limit)
33
-	//	if err != nil {
34
-	//
35
-	//	} else {
36
-	//		this.ServeSuccessJSON(map[string]interface{}{
37
-	//			"list": list,
38
-	//			"total":total,
39
-	//		})
40
-	//
41
-	//	}
42
-	//} else {
43
-	//
44
-	//
45
-	//
46
-	//}
17
+	active_status,_ := this.GetInt64("active_status")
18
+	depth_active_status,_ := this.GetInt64("depth_active_status")
19
+	start_time := this.GetString("start_time")
20
+	end_time := this.GetString("end_time")
21
+	province,_ := this.GetInt64("province")
22
+	city,_ := this.GetInt64("city")
23
+	district,_ := this.GetInt64("district")
24
+	follow,_ := this.GetInt64("follow")
25
+	keyword := this.GetString("keyword")
26
+	page, _ := this.GetInt64("page", 0)
27
+	limit, _ := this.GetInt64("limit", 0)
28
+	if page <= 0 {
29
+		page = 1
30
+	}
31
+	if limit <= 0 {
32
+		limit = 7
33
+	}
47 34
 
48
-}
35
+	timeLayout := "2006-01-02"
36
+	loc, _ := time.LoadLocation("Local")
37
+	var startTime int64
38
+	if len(start_time) > 0 {
39
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", start_time+" 00:00:00", loc)
40
+		if err != nil {
41
+			fmt.Println(err)
42
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
43
+			return
44
+		}
45
+		startTime = theTime.Unix()
46
+	}
47
+	var endTime int64
48
+	if len(end_time) > 0 {
49
+		theTime, err := time.ParseInLocation(timeLayout+" 15:04:05", end_time+" 23:59:59", loc)
50
+		if err != nil {
51
+			utils.ErrorLog(err.Error())
52
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
53
+			return
54
+		}
55
+		endTime = theTime.Unix()
56
+	}
57
+
58
+	adminInfo := this.GetAdminInfo()
59
+	if adminInfo.Admin.IsSuperAdmin == 1 {
60
+		list, err, total := service.GetAllOrgList(active_status,depth_active_status,startTime,endTime,province,city,district,follow,keyword,page,limit)
61
+		if err != nil {
49 62
 
63
+		} else {
64
+			this.ServeSuccessJSON(map[string]interface{}{
65
+				"list": list,
66
+				"total":total,
67
+			})
68
+		}
69
+	} else {
70
+
71
+	}
72
+}
50 73
 
51
-func (this *OrgAPIController) GetOrgDetail() {
74
+func (this *OrgAPIController) GetOrgInfo() {
52 75
 	org_id, _:=this.GetInt64("org_id",0)
53 76
 	info, err := service.GetOrgDetailInfo(org_id)
54
-	if err != nil {
77
+	province, _ := service.GetDistrictsById(info.Province)
78
+	city, _ := service.GetDistrictsById(info.City)
79
+	district, _ := service.GetDistrictsById(info.District)
80
+
81
+	orgType, err := service.GetAllOrgType()
55 82
 
83
+	if err != nil {
84
+		this.ErrorLog("错误:%v", err)
85
+		return
56 86
 	} else {
57 87
 		this.ServeSuccessJSON(map[string]interface{}{
58 88
 			"info": info,
89
+			"area":province.Name+city.Name+district.Name,
90
+			"org_type":orgType,
59 91
 		})
60 92
 	}
61 93
 }
62 94
 
95
+func (this *OrgAPIController) GetOrgDialysisOrderStatistics() {
96
+	org_id, _:=this.GetInt64("org_id",0)
97
+	range_data := this.GetString("range_data")
98
+	range_type, _ := this.GetInt64("range_type")
99
+	statistics_type, _ := this.GetInt64("type")
100
+	var rangeDate *time.Time
101
+	var parseDateErr error
102
+	var rangeTimeStamp int64
103
+
63 104
 
64 105
 
65
-func (this *OrgAPIController) GetOrgDialysisOrderStatistics() {
66
-	//org_id, _:=this.GetInt64("org_id",0)
67
-	//range_data := this.GetString("range_data")
68
-	//range_type, _ := this.GetInt64("range_type")
69
-	//statistics_type, _ := this.GetInt64("type")
70
-	//
71
-	//
72
-	//var rangeDate *time.Time
73
-	//var parseDateErr error
74
-	//var rangeTimeStamp int64
75
-	//
76
-	//if len(range_data) > 0 {
77
-	//	rangeDate, parseDateErr = utils.ParseTimeStringToTime("2006-01-02", range_data)
78
-	//	if parseDateErr != nil {
79
-	//		this.ErrorLog("日期(%v)解析错误:%v", range_data, parseDateErr)
80
-	//		return
81
-	//	}
82
-	//	rangeTimeStamp = rangeDate.Unix()
83
-	//} else {
84
-	//	rangeTimeStamp = 0
85
-	//}
86
-	//now := time.Now().Unix()
87
-	//
88
-	//info, err := service.GetOrgNewPatientInfo(org_id)
89
-	//if err != nil {
90
-	//
91
-	//} else {
92
-	//	this.ServeSuccessJSON(map[string]interface{}{
93
-	//		"info": info,
94
-	//	})
95
-	//}
106
+
107
+	var orgDialysisOrderStatistics []*admin_models.Statistics
108
+
109
+	switch range_type{
110
+	case 1: //今天
111
+		if len(range_data) > 0 {
112
+			rangeDate, parseDateErr = utils.ParseTimeStringToTime("2006-01-02", range_data)
113
+			if parseDateErr != nil {
114
+				this.ErrorLog("日期(%v)解析错误:%v", range_data, parseDateErr)
115
+				return
116
+			}
117
+			rangeTimeStamp = rangeDate.Unix()
118
+		} else {
119
+			rangeTimeStamp = 0
120
+		}
121
+		now := time.Now().Unix()
122
+		count , err := service.GetOrgDialysisCount(statistics_type,org_id,rangeTimeStamp,now)
123
+		if err != nil {
124
+			this.ErrorLog("错误:%v", err)
125
+			return
126
+
127
+		} else {
128
+			this.ServeSuccessJSON(map[string]interface{}{
129
+				"count": count,
130
+			})
131
+		}
132
+		break
133
+	case 2:  //昨天
134
+		if len(range_data) > 0 {
135
+			rangeDate, parseDateErr = utils.ParseTimeStringToTime("2006-01-02", range_data)
136
+			if parseDateErr != nil {
137
+				this.ErrorLog("日期(%v)解析错误:%v", range_data, parseDateErr)
138
+				return
139
+			}
140
+			rangeTimeStamp = rangeDate.Unix()
141
+		} else {
142
+			rangeTimeStamp = 0
143
+		}
144
+		now := time.Now().Unix()
145
+		count , err := service.GetOrgDialysisCount(statistics_type,org_id,rangeTimeStamp,now)
146
+		if err != nil {
147
+			this.ErrorLog("错误:%v", err)
148
+			return
149
+
150
+		} else {
151
+			this.ServeSuccessJSON(map[string]interface{}{
152
+				"count": count,
153
+			})
154
+		}
155
+		break
156
+	case 3://一周
157
+		var err error
158
+		orgDialysisOrderStatistics, err = service.GetWeekOrgDialysisCount(statistics_type, org_id)
159
+		if err != nil {
160
+			this.ErrorLog("错误:%v", err)
161
+			return
162
+		} else {
163
+			this.ServeSuccessJSON(map[string]interface{}{
164
+				"list": orgDialysisOrderStatistics,
165
+			})
166
+		}
167
+		break
168
+	case 4://一个月
169
+		var err error
170
+		orgDialysisOrderStatistics, err = service.GetMonthOrgDialysisCount(statistics_type, org_id)
171
+		if err != nil {
172
+			this.ErrorLog("错误:%v", err)
173
+			return
174
+		} else {
175
+			this.ServeSuccessJSON(map[string]interface{}{
176
+				"list": orgDialysisOrderStatistics,
177
+			})
178
+		}
179
+		break
180
+	case 5://三个月
181
+		var err error
182
+		orgDialysisOrderStatistics, err = service.GetThreeMonthOrgDialysisCount(statistics_type, org_id)
183
+		if err != nil {
184
+			this.ErrorLog("错误:%v", err)
185
+			return
186
+		} else {
187
+			this.ServeSuccessJSON(map[string]interface{}{
188
+				"list": orgDialysisOrderStatistics,
189
+			})
190
+		}
191
+		break
192
+	case 6://半年
193
+		var err error
194
+		orgDialysisOrderStatistics, err = service.GetSixMonthOrgDialysisCount(statistics_type, org_id)
195
+		if err != nil {
196
+			this.ErrorLog("错误:%v", err)
197
+			return
198
+		} else {
199
+			this.ServeSuccessJSON(map[string]interface{}{
200
+				"list": orgDialysisOrderStatistics,
201
+			})
202
+		}
203
+		break
204
+	case 7://一年
205
+		var err error
206
+		orgDialysisOrderStatistics, err = service.GetYearOrgDialysisCount(statistics_type, org_id)
207
+		if err != nil {
208
+			this.ErrorLog("错误:%v", err)
209
+			return
210
+		} else {
211
+			this.ServeSuccessJSON(map[string]interface{}{
212
+				"list": orgDialysisOrderStatistics,
213
+			})
214
+		}
215
+		break
216
+	}
96 217
 }
97 218
 
98 219
 func (c *OrgAPIController) GetDistrictsByUpid() {
99 220
 	id, _ := c.GetInt64("id", 0)
100 221
 	citys, _ := service.GetDistrictsByUpid(id)
101
-
102 222
 	c.ServeSuccessJSON(map[string]interface{}{
103 223
 		"citys": citys,
104 224
 	})

+ 16 - 2
models/org_models.go View File

@@ -27,6 +27,7 @@ type Org struct {
27 27
 	ContactName       string            `gorm:"column:contact_name" json:"contact_name"`
28 28
 	OrgGallery        []*OrgGallery     `gorm:"ForeignKey:OrgId" json:"org_gallery"`
29 29
 	AdminUserLoginLog AdminUserLoginLog `gorm:"ForeignKey:OrgId" json:"log"`
30
+	AdminUser         AdminUser         `gorm:"ForeignKey:Id" json:"admin"`
30 31
 }
31 32
 
32 33
 func (Org) TableName() string {
@@ -104,8 +105,6 @@ func (Illness) TableName() string {
104 105
 	return "sgj_user_illness"
105 106
 }
106 107
 
107
-
108
-
109 108
 type District struct {
110 109
 	ID        int64  `gorm:"column:id" json:"id" form:"id"`
111 110
 	Name      string `gorm:"column:name" json:"name" form:"name"`
@@ -122,3 +121,18 @@ type District struct {
122 121
 func (District) TableName() string {
123 122
 	return "sgj_user_district"
124 123
 }
124
+
125
+type UserOrgType struct {
126
+	ID          int64  `gorm:"column:id" json:"id"`
127
+	Name        string `gorm:"column:name" json:"name"`
128
+	ShortName   string `gorm:"column:short_name" json:"short_name"`
129
+	Pid         int64  `gorm:"column:pid" json:"pid"`
130
+	Status      int64  `gorm:"column:status" json:"status"`
131
+	CreatedTime int64  `gorm:"column:created_time" json:"created_time"`
132
+	UpdatedTime int64  `gorm:"column:updated_time" json:"updated_time"`
133
+	SortNo      int64  `gorm:"column:sort_no" json:"sort_no"`
134
+}
135
+
136
+func (UserOrgType) TableName() string {
137
+	return "sgj_user_org_type"
138
+}

+ 20 - 20
service/admin_service.go View File

@@ -383,7 +383,7 @@ func GetPatientTotalCount() (int64, error) {
383 383
 // 获取一段时间内的活跃账户数
384 384
 func GetActiveAdminUserCount(from int64, to int64) (int64, error) {
385 385
 	var count int64
386
-	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, to).Rows()
386
+	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()
387 387
 	if err != nil {
388 388
 		return 0, err
389 389
 	}
@@ -396,7 +396,7 @@ func GetActiveAdminUserCount(from int64, to int64) (int64, error) {
396 396
 // 获取所有机构账户数量
397 397
 func GetAdminUserTotalCount() (int64, error) {
398 398
 	var count int64
399
-	rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM sgj_user_admin_login_log").Rows()
399
+	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()
400 400
 	if err != nil {
401 401
 		return 0, err
402 402
 	}
@@ -419,7 +419,7 @@ func GetRegistedOrgCount(from int64, to int64) (int64, error) {
419 419
 // 获取一段时间内的活跃机构数
420 420
 func GetActiveOrgCount(from int64, to int64) (int64, error) {
421 421
 	var count int64
422
-	rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT org_id) AS count FROM sgj_user_admin_login_log WHERE ctime >= ? AND ctime <= ?", from, to).Joins("JOIN sgj_xt.xt_dialysis_order as order ON sgj_user_admin_login_log.org_id = order.user_org_id").Rows()
422
+	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()
423 423
 	if err != nil {
424 424
 		return 0, err
425 425
 	}
@@ -432,7 +432,7 @@ func GetActiveOrgCount(from int64, to int64) (int64, error) {
432 432
 // 获取所有活跃机构数
433 433
 func GetActiveOrgTotalCount() (int64, error) {
434 434
 	var count int64
435
-	rows, err := readUserDb.Raw("SELECT COUNT(DISTINCT org_id) AS count FROM sgj_user_admin_login_log").Joins("JOIN sgj_xt.xt_dialysis_order as order ON sgj_user_admin_login_log.org_id = order.user_org_id").Rows()
435
+	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()
436 436
 	if err != nil {
437 437
 		return 0, err
438 438
 	}
@@ -457,14 +457,14 @@ func GetWeekRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err e
457 457
 
458 458
 //获取近七天每天的机构活跃总量
459 459
 func GetWeekActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
460
-	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 GROUP BY date(from_unixtime(ctime));")
460
+	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));")
461 461
 	err = db.Scan(&weekStatistics).Error
462 462
 	return
463 463
 }
464 464
 
465 465
 //获取近七天每天的机构活跃账号总量
466 466
 func GetWeekActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
467
-	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 7 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime))  AND operate_type = 1 GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
467
+	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 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));").Scan(&weekStatistics).Error
468 468
 	return
469 469
 }
470 470
 
@@ -517,14 +517,14 @@ func GetMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err
517 517
 
518 518
 //获取近30天每天的机构活跃总量
519 519
 func GetMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
520
-	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as month,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 month").Scan(&weekStatistics).Error
520
+	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
521 521
 	return
522 522
 }
523 523
 
524 524
 
525 525
 //获取近30天每天的机构活跃账号总量
526 526
 func GetMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
527
-	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 30 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime))  AND operate_type = 1 GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
527
+	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 30 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 GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
528 528
 	return
529 529
 }
530 530
 
@@ -568,26 +568,26 @@ func GetMonthNewPatientTotalCount() (int64,  error) {
568 568
 
569 569
 //获取近3个月每个月的注册机构总量
570 570
 func GetThreeMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
571
-	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
571
+	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
572 572
 	return
573 573
 }
574 574
 
575 575
 
576 576
 //获取近3个月每个月的机构活跃账号总量
577 577
 func GetThreeMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
578
-	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 3 month),'%Y-%m')  AND operate_type = 1 group by times").Scan(&weekStatistics).Error
578
+	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 3 month),'%Y-%m')  AND sgj_user_admin_login_log.app_type = 3  AND sgj_user_admin_login_log.operate_type = 1 group by times").Scan(&weekStatistics).Error
579 579
 	return
580 580
 }
581 581
 
582 582
 //获取近3个月每个月的机构活跃总量
583 583
 func GetThreeMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
584
-	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as month,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 3 month),'%Y-%m')  group by month").Scan(&weekStatistics).Error
584
+	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
585 585
 	return
586 586
 }
587 587
 
588 588
 //获取近3个月每个月机构新增病人总量
589 589
 func GetThreeMonthNewPatientCount() (weekStatistics []*admin_models.Statistics, err error) {
590
-	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 3 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
590
+	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 3 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
591 591
 	return
592 592
 }
593 593
 
@@ -625,28 +625,28 @@ func GetThreeMonthNewPatientTotalCount() (int64,  error) {
625 625
 
626 626
 //获取近半年每个月的注册机构总量
627 627
 func GetSixMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
628
-	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
628
+	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
629 629
 	return
630 630
 }
631 631
 
632 632
 
633 633
 //获取近半年每个月的机构活跃账号总量
634 634
 func GetSixMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
635
-	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') group by times").Scan(&weekStatistics).Error
635
+	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') AND sgj_user_admin_login_log.app_type = 3  AND sgj_user_admin_login_log.operate_type = 1 group by times").Scan(&weekStatistics).Error
636 636
 	return
637 637
 }
638 638
 
639 639
 
640 640
 //获取近半年每个月的机构活跃总量
641 641
 func GetSixMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
642
-	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as month,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 6 month),'%Y-%m')  group by month").Scan(&weekStatistics).Error
642
+	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
643 643
 	return
644 644
 }
645 645
 
646 646
 
647 647
 //获取近半年每个月机构新增病人总量
648 648
 func GetSixMonthNewPatientCount() (weekStatistics []*admin_models.Statistics, 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') group by times").Scan(&weekStatistics).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') group by times").Scan(&weekStatistics).Error
650 650
 	return
651 651
 }
652 652
 
@@ -684,26 +684,26 @@ func GetSixMonthNewPatientTotalCount() (int64,  error) {
684 684
 
685 685
 //获取近1年每个月的注册机构总量
686 686
 func GetYearRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
687
-	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
687
+	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
688 688
 	return
689 689
 }
690 690
 
691 691
 
692 692
 //获取近1年每个月的机构活跃账号总量
693 693
 func GetYearActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
694
-	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') group by times").Scan(&weekStatistics).Error
694
+	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') AND sgj_user_admin_login_log.app_type = 3  AND sgj_user_admin_login_log.operate_type = 1 group by times").Scan(&weekStatistics).Error
695 695
 	return
696 696
 }
697 697
 
698 698
 //获取近1年每个月的机构活跃总量
699 699
 func GetYearActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
700
-	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as month,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 12 month),'%Y-%m')  group by month").Scan(&weekStatistics).Error
700
+	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
701 701
 	return
702 702
 }
703 703
 
704 704
 //获取近1年每个月机构新增病人总量
705 705
 func GetYearNewPatientCount() (weekStatistics []*admin_models.Statistics, err error) {
706
-	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 12 month),'%Y-%m') AND status > 0 group by times").Scan(&weekStatistics).Error
706
+	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 12 month),'%Y-%m') AND status > 0 group by times").Scan(&weekStatistics).Error
707 707
 	return
708 708
 }
709 709
 

+ 405 - 29
service/org_service.go View File

@@ -2,18 +2,20 @@ package service
2 2
 
3 3
 import (
4 4
 	"XT_Admin_Api/models"
5
+	"XT_Admin_Api/models/admin_models"
5 6
 	"XT_Admin_Api/utils"
7
+	"fmt"
6 8
 	"github.com/jinzhu/gorm"
7 9
 	"time"
8 10
 )
9 11
 
10 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){
11 13
 	offset := (page - 1) * limit
12
-
14
+	fmt.Println(offset)
13 15
 	db := readUserDb.Model(&models.Org{})
14 16
 	if len(keyword) > 0{
15 17
 		likeKey := "%" + keyword + "%"
16
-		db = db.Where("contact_name  LIKE ?",likeKey)
18
+		db = db.Where("contact_name  LIKE ? Or org_name LIKE ? Or org_short_name Like ? ",likeKey,likeKey,likeKey)
17 19
 	}else{
18 20
 
19 21
 		switch active_status {
@@ -23,13 +25,13 @@ func GetAllOrgList(active_status int64,depth_active_status int64,start_time int6
23 25
 			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",zeroHourTimeOfToday.Unix(),now.Unix())
24 26
 			break
25 27
 		case 2:
26
-			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")
28
+			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 ")
27 29
 			break
28 30
 		case 3:
29
-			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")
31
+			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 ")
30 32
 			break
31 33
 		case 4:
32
-			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")
34
+			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 ")
33 35
 			break
34 36
 		}
35 37
 
@@ -37,23 +39,23 @@ func GetAllOrgList(active_status int64,depth_active_status int64,start_time int6
37 39
 		case 1:
38 40
 			now := time.Now()
39 41
 			zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
40
-			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",zeroHourTimeOfToday.Unix(),now.Unix())
41
-			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",zeroHourTimeOfToday.Unix(),now.Unix())
42
+			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())
43
+			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 ")
42 44
 
43 45
 			break
44 46
 		case 2:
45
-			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")
46
-			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")
47
+			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 ")
48
+			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 49
 
48 50
 			break
49 51
 		case 3:
50
-			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")
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_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")
52
+			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 ")
53
+			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 ")
52 54
 
53 55
 			break
54 56
 		case 4:
55
-			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")
56
-			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")
57
+			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 ")
58
+			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 ")
57 59
 
58 60
 			break
59 61
 		}
@@ -62,49 +64,423 @@ func GetAllOrgList(active_status int64,depth_active_status int64,start_time int6
62 64
 		}
63 65
 
64 66
 		if city > 0{
65
-			db = db.Where("sgj_user_org.province = ?",city)
67
+			db = db.Where("sgj_user_org.city = ?",city)
66 68
 		}
67 69
 
68 70
 		if district > 0{
69
-			db = db.Where("sgj_user_org.province = ?",district)
71
+			db = db.Where("sgj_user_org.district = ?",district)
70 72
 		}
71 73
 
72 74
 		if start_time != 0 {
73
-			db = db.Where("ctime>=?", start_time)
75
+			db = db.Where("sgj_user_org.ctime>=?", start_time)
74 76
 		}
75 77
 		if end_time != 0 {
76
-			db = db.Where("ctime<=?", end_time)
78
+			db = db.Where("sgj_user_org.ctime<=?", end_time)
77 79
 		}
78 80
 
79 81
 	}
80
-	err = db.Where("status = 1").Count(&total).Offset(offset).Limit(limit).Find(&list).Error
82
+	err = db.Where("sgj_user_org.status = 1").Preload("AdminUserLoginLog", func(db *gorm.DB) *gorm.DB {
83
+		return db.Model(&models.AdminUserLoginLog{}).Where("id = (SELECT max(id))")
84
+	}).Count(&total).Offset(offset).Limit(limit).Group("id").Find(&list).Error
81 85
 	return
82 86
 }
83 87
 
84 88
 
85 89
 func GetOrgDetailInfo(org_id int64) (info models.Org, err error){
86
-	err = readUserDb.Model(&models.Org{}).Where("org_id = ? AND status = 1",org_id).Preload("AdminUserLoginLog", func(db *gorm.DB) *gorm.DB {
87
-		return db.Model(&models.AdminUserLoginLog{}).Where("status = 1 AND id = (SELECT max(id))")
88
-	}).Find(&info).Error
90
+	err = readUserDb.Model(&models.Org{}).Where("id = ? AND status = 1",org_id).Preload("AdminUserLoginLog", func(db *gorm.DB) *gorm.DB {
91
+		return db.Model(&models.AdminUserLoginLog{}).Where("id = (SELECT max(id))")
92
+	}).Preload("AdminUser","status = 1").Find(&info).Error
89 93
 	return
90 94
 }
91 95
 
96
+func GetDistrictsById(id int64)(district models.District, err error){
97
+	err = readUserDb.Model(&models.District{}).Where("id = ? ", id).First(&district).Error
98
+	return
99
+}
92 100
 
101
+func GetAllOrgType()(types []*models.OrgType, err error){
102
+	err = readUserDb.Model(&models.OrgType{}).Find(&types).Error
103
+	return
104
+}
105
+//设置今天和昨天的数据
106
+func GetOrgDialysisCount(statices_type int64, org_id int64, from int64,to int64) (count int64, err error){
107
+	var counts int64
93 108
 
94
-func GetOrgNewPatientInfo(org_id int64, from int64,to int64) (count int64, err error){
109
+	switch statices_type {
110
+	case 1: //病人管理
111
+		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()
112
+		if err != nil {
113
+			return 0, err
114
+		}
115
+		if rows.Next() {
116
+			rows.Scan(&counts)
117
+		}
118
+		break
119
+	case 2: //透析处方
120
+		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()
121
+		if err != nil {
122
+			return 0, err
123
+		}
124
+		if rows.Next() {
125
+			rows.Scan(&counts)
126
+		}
127
+		break
128
+	case 3: //接诊评估
129
+		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()
130
+		if err != nil {
131
+			return 0, err
132
+		}
133
+		if rows.Next() {
134
+			rows.Scan(&counts)
135
+		}
136
+		break
137
+	case 4: //透前评估
138
+		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()
139
+		if err != nil {
140
+			return 0, err
141
+		}
142
+		if rows.Next() {
143
+			rows.Scan(&counts)
144
+		}
145
+		break
146
+	case 5://临时医嘱
147
+		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()
148
+		if err != nil {
149
+			return 0, err
150
+		}
151
+		if rows.Next() {
152
+			rows.Scan(&counts)
153
+		}
154
+		break
155
+	case 6: //双人核对
156
+		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()
157
+		if err != nil {
158
+			return 0, err
159
+		}
160
+		if rows.Next() {
161
+			rows.Scan(&counts)
162
+		}
163
+		break
164
+	case 7: //透析上机
165
+		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()
166
+		if err != nil {
167
+			return 0, err
168
+		}
169
+		if rows.Next() {
170
+			rows.Scan(&counts)
171
+		}
172
+		break
95 173
 
96
-	var counts int64
97
-	rows, err := readDb.Raw("SELECT COUNT(DISTINCT id) AS count FROM xt_patients WHERE org_id = ? AND created_time >= ? AND created_time <= ?",org_id ,from, to).Rows()
98
-	if err != nil {
99
-		return 0, err
100
-	}
101
-	if rows.Next() {
102
-		rows.Scan(&counts)
174
+	case 8: //透析监测
175
+		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()
176
+		if err != nil {
177
+			return 0, err
178
+		}
179
+		if rows.Next() {
180
+			rows.Scan(&counts)
181
+		}
182
+		break
183
+	case 9: //透析下机
184
+		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()
185
+		if err != nil {
186
+			return 0, err
187
+		}
188
+		if rows.Next() {
189
+			rows.Scan(&counts)
190
+		}
191
+		break
192
+	case 10: //透后评估
193
+		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()
194
+		if err != nil {
195
+			return 0, err
196
+		}
197
+		if rows.Next() {
198
+			rows.Scan(&counts)
199
+		}
200
+		break
201
+	case 11: //入库单
202
+		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()
203
+		if err != nil {
204
+			return 0, err
205
+		}
206
+		if rows.Next() {
207
+			rows.Scan(&counts)
208
+		}
209
+		break
210
+	case 12: //出库单
211
+		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()
212
+		if err != nil {
213
+			return 0, err
214
+		}
215
+		if rows.Next() {
216
+			rows.Scan(&counts)
217
+		}
218
+		break
103 219
 	}
104 220
 	return counts, nil
105 221
 }
106 222
 
223
+//获取近七天的数据
224
+func GetWeekOrgDialysisCount(statices_type int64,org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
225
+	fmt.Println(statices_type)
226
+
227
+	switch statices_type {
228
+	case 1: //病人管理
229
+		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 7 DAY) <= date(from_unixtime(created_time)) AND status = 1  AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
230
+
231
+		break
232
+	case 2: //透析处方
233
+		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 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
234
+
235
+		break
236
+	case 3: //接诊评估
237
+		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 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
238
+
239
+		break
240
+	case 4: //透前评估
241
+		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 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
242
+		break
243
+
244
+	case 5://临时医嘱
245
+		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 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
246
+
247
+		break
248
+	case 6: //双人核对
249
+		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 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
250
+
251
+		break
252
+	case 7: //透析上机
253
+		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 7 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
254
+		break
255
+
256
+	case 8: //透析监测
257
+		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 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ?  GROUP BY times",org_id).Scan(&weekStatistics).Error
258
+		break
259
+	case 9: //透析下机
260
+		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 7 DAY) <= date(from_unixtime(created_time)) AND stage = 2 AND status = 1  AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
261
+
262
+		break
263
+	case 10: //透后评估
264
+		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 7 DAY) <= date(from_unixtime(created_time)) AND status = 1  AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
265
+		break
266
+	case 11: //入库单
267
+		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 7 DAY) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ?  GROUP BY times",org_id).Scan(&weekStatistics).Error
268
+		break
269
+	case 12: //出库单
270
+		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 7 DAY) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
271
+		break
272
+	}
273
+
274
+	return
275
+}
276
+
277
+
278
+
279
+func GetMonthOrgDialysisCount(statices_type int64,org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
280
+	switch statices_type {
281
+	case 1: //病人管理
282
+		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 30 DAY) <= date(from_unixtime(created_time)) AND status = 1  AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
283
+
284
+		break
285
+	case 2: //透析处方
286
+		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 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
287
+
288
+		break
289
+	case 3: //接诊评估
290
+		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 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
107 291
 
292
+		break
293
+	case 4: //透前评估
294
+		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 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
295
+		break
296
+
297
+	case 5://临时医嘱
298
+		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 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
299
+
300
+		break
301
+	case 6: //双人核对
302
+		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 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
303
+
304
+		break
305
+	case 7: //透析下机
306
+		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 30 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
307
+		break
308
+
309
+	case 8: //透析监测
310
+		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 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ?  GROUP BY times",org_id).Scan(&weekStatistics).Error
311
+		break
312
+	case 9: //透析下机
313
+		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 30 DAY) <= date(from_unixtime(created_time)) AND stage = 2 AND status = 1  AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
314
+
315
+		break
316
+	case 10: //透后评估
317
+		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 30 DAY) <= date(from_unixtime(created_time)) AND status = 1  AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
318
+		break
319
+	case 11: //入库单
320
+		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 30 DAY) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ?  GROUP BY times",org_id).Scan(&weekStatistics).Error
321
+		break
322
+	case 12: //出库单
323
+		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 30 DAY) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
324
+		break
325
+	}
326
+	return
327
+}
328
+
329
+
330
+func GetThreeMonthOrgDialysisCount(statices_type int64,org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
331
+	switch statices_type {
332
+	case 1: //病人管理
333
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_patients  where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1  AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
334
+
335
+		break
336
+	case 2: //透析处方
337
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_dialysis_prescription  where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
338
+
339
+		break
340
+	case 3: //接诊评估
341
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_receive_treatment_asses  where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
342
+
343
+		break
344
+	case 4: //透前评估
345
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_assessment_before_dislysis  where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
346
+		break
347
+
348
+	case 5://临时医嘱
349
+		err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_doctor_advice  where DATE_SUB(CURDATE(),INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
350
+
351
+		break
352
+	case 6: //双人核对
353
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_double_check  where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
354
+
355
+		break
356
+	case 7: //透析上机
357
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_dialysis_order  where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= 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
358
+		break
359
+
360
+	case 8: //透析监测
361
+		err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_monitoring_record  where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times ",org_id).Scan(&weekStatistics).Error
362
+		break
363
+	case 9: //透析下机
364
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_dialysis_order  where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND stage = 2 AND status = 1  AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
365
+
366
+		break
367
+	case 10: //透后评估
368
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_assessment_after_dislysis  where DATE_SUB(CURDATE(),INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1  AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
369
+		break
370
+	case 11: //入库单
371
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times  from xt_warehouse  where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times ",org_id).Scan(&weekStatistics).Error
372
+		break
373
+	case 12: //出库单
374
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times  from xt_warehouse_out  where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
375
+		break
376
+	}
377
+	return
378
+}
379
+
380
+
381
+
382
+func GetSixMonthOrgDialysisCount(statices_type int64,org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
383
+	switch statices_type {
384
+	case 1: //病人管理
385
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_patients  where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1  AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
386
+
387
+		break
388
+	case 2: //透析处方
389
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_dialysis_prescription  where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
390
+
391
+		break
392
+	case 3: //接诊评估
393
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_receive_treatment_asses  where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
394
+
395
+		break
396
+	case 4: //透前评估
397
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_assessment_before_dislysis  where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
398
+		break
399
+
400
+	case 5://临时医嘱
401
+		err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_doctor_advice  where DATE_SUB(CURDATE(),INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
402
+
403
+		break
404
+	case 6: //双人核对
405
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_double_check  where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
406
+
407
+		break
408
+	case 7: //透析上机
409
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_dialysis_order  where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= 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
410
+		break
411
+
412
+	case 8: //透析监测
413
+		err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_monitoring_record  where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times ",org_id).Scan(&weekStatistics).Error
414
+		break
415
+	case 9: //透析下机
416
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_dialysis_order  where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND stage = 2 AND status = 1  AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
417
+
418
+		break
419
+	case 10: //透后评估
420
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_assessment_after_dislysis  where DATE_SUB(CURDATE(),INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1  AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
421
+		break
422
+	case 11: //入库单
423
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times  from xt_warehouse  where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times ",org_id).Scan(&weekStatistics).Error
424
+		break
425
+	case 12: //出库单
426
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times  from xt_warehouse_out  where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
427
+		break
428
+	}
429
+	return
430
+}
431
+
432
+
433
+
434
+
435
+func GetYearOrgDialysisCount(statices_type int64,org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
436
+	switch statices_type {
437
+	case 1: //病人管理
438
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_patients  where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1  AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
439
+
440
+		break
441
+	case 2: //透析处方
442
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_dialysis_prescription  where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
443
+
444
+		break
445
+	case 3: //接诊评估
446
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_receive_treatment_asses  where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
447
+
448
+		break
449
+	case 4: //透前评估
450
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_assessment_before_dislysis  where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
451
+		break
452
+
453
+	case 5://临时医嘱
454
+		err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_doctor_advice  where DATE_SUB(CURDATE(),INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
455
+
456
+		break
457
+	case 6: //双人核对
458
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_double_check  where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
459
+
460
+		break
461
+	case 7: //透析上机
462
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_dialysis_order  where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= 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
463
+		break
464
+
465
+	case 8: //透析监测
466
+		err = readDb.Raw("select count(distinct patient_id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_monitoring_record  where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1 AND user_org_id = ? GROUP BY times ",org_id).Scan(&weekStatistics).Error
467
+		break
468
+	case 9: //透析下机
469
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_dialysis_order  where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND stage = 2 AND status = 1  AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
470
+
471
+		break
472
+	case 10: //透后评估
473
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_assessment_after_dislysis  where DATE_SUB(CURDATE(),INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1  AND user_org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
474
+		break
475
+	case 11: //入库单
476
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times  from xt_warehouse  where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times ",org_id).Scan(&weekStatistics).Error
477
+		break
478
+	case 12: //出库单
479
+		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times  from xt_warehouse_out  where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(ctime)) AND status = 1 AND org_id = ? GROUP BY times",org_id).Scan(&weekStatistics).Error
480
+		break
481
+	}
482
+	return
483
+}
108 484
 
109 485
 func GetDistrictsByUpid(id int64) (dis []*models.District, err error) {
110 486
 	err = readUserDb.Model(&models.District{}).Where("upid=?", id).Find(&dis).Error