|
@@ -130,36 +130,22 @@ func GetRegistedOrgCount(from int64, to int64) (int64, error) {
|
130
|
130
|
|
131
|
131
|
// 获取一段时间内的活跃机构数
|
132
|
132
|
func GetActiveOrgCount(from int64, to int64) (int64, error) {
|
133
|
|
- var count int64
|
134
|
|
-
|
135
|
|
- db := readDb.Raw("SELECT COUNT(DISTINCT user_org_id) AS count FROM xt_dialysis_order where created_time >= ? AND created_time <= ? AND status = 1 ", from, to)
|
136
|
|
- rows, err := db.Rows()
|
137
|
|
- defer rows.Close()
|
|
133
|
+ var org []*Org
|
|
134
|
+ //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 log JOIN (Select d.user_org_id from (Select new_role.user_org_id from (Select count(*) as count,org_id as user_org_id from sgj_users.sgj_user_admin_role role where role.`user_type` = 2 OR role.`user_type` = 3 Group by role.org_id) new_role where new_role.count > 2) d JOIN (Select user_org_id from (Select count(*) as count,user_org_id from sgj_xt.xt_patients where status = 1 Group by user_org_id) new_patient where new_patient.count > 3) c On d.user_org_id = c.user_org_id) new_user_org ON new_user_org.user_org_id = log.org_id where ctime >= ? AND ctime <= ? Group by log.org_id", from, to).Scan(&org)
|
|
135
|
+ readUserDb.Raw("Select org_id from sgj_user_admin_login_log log JOIN (Select d.user_org_id from (Select new_role.user_org_id from (Select count(*) as count,org_id as user_org_id from sgj_users.sgj_user_admin_role role where role.`user_type` = 2 OR role.`user_type` = 3 Group by role.org_id) new_role where new_role.count > 2) d JOIN (Select user_org_id from (Select count(*) as count,user_org_id from sgj_xt.xt_patients where status = 1 Group by user_org_id) new_patient where new_patient.count > 3) c On d.user_org_id = c.user_org_id) new_user_org ON new_user_org.user_org_id = log.org_id where ctime >= ? AND ctime <= ? Group by log.org_id", from, to).Scan(&org)
|
|
136
|
+ return int64(len(org)), nil
|
|
137
|
+}
|
138
|
138
|
|
139
|
|
- if err != nil {
|
140
|
|
- return 0, err
|
141
|
|
- }
|
142
|
|
- if rows.Next() {
|
143
|
|
- rows.Scan(&count)
|
144
|
|
- }
|
145
|
|
- return count, nil
|
|
139
|
+type Org struct {
|
|
140
|
+ OrgId int64
|
146
|
141
|
}
|
147
|
142
|
|
148
|
143
|
// 获取所有活跃机构数
|
149
|
144
|
func GetActiveOrgTotalCount() (int64, error) {
|
150
|
|
- var count int64
|
151
|
|
-
|
152
|
|
- db := readDb.Raw("SELECT COUNT(DISTINCT user_org_id) AS count FROM sgj_xt.xt_dialysis_order Where status = 1")
|
153
|
|
- rows, err := db.Rows()
|
154
|
|
- defer rows.Close()
|
155
|
|
- //rows, err := readDb.Raw("SELECT COUNT(DISTINCT user_org_id) AS count FROM sgj_xt.xt_dialysis_order Where status = 1").Rows()
|
156
|
|
- if err != nil {
|
157
|
|
- return 0, err
|
158
|
|
- }
|
159
|
|
- if rows.Next() {
|
160
|
|
- rows.Scan(&count)
|
161
|
|
- }
|
162
|
|
- return count, nil
|
|
145
|
+ var org []*Org
|
|
146
|
+ readUserDb.Raw("Select org_id from sgj_user_admin_login_log log JOIN (Select d.user_org_id from (Select new_role.user_org_id from (Select count(*) as count,org_id as user_org_id from sgj_users.sgj_user_admin_role role where role.`user_type` = 2 OR role.`user_type` = 3 Group by role.org_id) new_role where new_role.count > 2) d JOIN (Select user_org_id from (Select count(*) as count,user_org_id from sgj_xt.xt_patients where status = 1 Group by user_org_id) new_patient where new_patient.count > 3) c On d.user_org_id = c.user_org_id) new_user_org ON new_user_org.user_org_id = log.org_id Group by log.org_id").Scan(&org)
|
|
147
|
+ fmt.Println(org)
|
|
148
|
+ return int64(len(org)), nil
|
163
|
149
|
}
|
164
|
150
|
|
165
|
151
|
//获取昨天的注册机构总量
|
|
@@ -170,7 +156,7 @@ func GetYesterDayRegistedOrgCount() (weekStatistics []*admin_models.Statistics,
|
170
|
156
|
|
171
|
157
|
//获取近昨天的的机构活跃总量
|
172
|
158
|
func GetYesterDayActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
|
173
|
|
- 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));")
|
|
159
|
+ 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 log JOIN (Select d.user_org_id from (Select new_role.user_org_id from (Select count(*) as count,org_id as user_org_id from sgj_users.sgj_user_admin_role role where role.`user_type` = 2 OR role.`user_type` = 3 Group by role.org_id) new_role where new_role.count > 2) d JOIN (Select user_org_id from (Select count(*) as count,user_org_id from sgj_xt.xt_patients where status = 1 Group by user_org_id) new_patient where new_patient.count > 3) c On d.user_org_id = c.user_org_id) new_user_org ON new_user_org.user_org_id = log.org_id where DATE_SUB(CURDATE(), INTERVAL 1 DAY) = date(from_unixtime(ctime)) Group by date(from_unixtime(ctime))")
|
174
|
160
|
err = db.Scan(&weekStatistics).Error
|
175
|
161
|
return
|
176
|
162
|
}
|
|
@@ -200,7 +186,9 @@ func GetWeekRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err e
|
200
|
186
|
|
201
|
187
|
//获取近七天每天的机构活跃总量
|
202
|
188
|
func GetWeekActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
|
203
|
|
- db := readDb.Raw("select count(DISTINCT(user_org_id)) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 GROUP BY date(from_unixtime(created_time));")
|
|
189
|
+ //db := readDb.Raw("select count(DISTINCT(user_org_id)) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time)) AND status = 1 GROUP BY date(from_unixtime(created_time));")
|
|
190
|
+ 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 log JOIN (Select d.user_org_id from (Select new_role.user_org_id from (Select count(*) as count,org_id as user_org_id from sgj_users.sgj_user_admin_role role where role.`user_type` = 2 OR role.`user_type` = 3 Group by role.org_id) new_role where new_role.count > 2) d JOIN (Select user_org_id from (Select count(*) as count,user_org_id from sgj_xt.xt_patients where status = 1 Group by user_org_id) new_patient where new_patient.count > 3) c On d.user_org_id = c.user_org_id) new_user_org ON new_user_org.user_org_id = log.org_id where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(ctime)) Group by date(from_unixtime(ctime))")
|
|
191
|
+
|
204
|
192
|
err = db.Scan(&weekStatistics).Error
|
205
|
193
|
return
|
206
|
194
|
}
|
|
@@ -225,7 +213,7 @@ func GetMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err
|
225
|
213
|
|
226
|
214
|
//获取近30天每天的机构活跃总量
|
227
|
215
|
func GetMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
|
228
|
|
- err = readDb.Raw("select count(DISTINCT(user_org_id)) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times from xt_dialysis_order where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND status = 1 GROUP BY date(from_unixtime(created_time));").Scan(&weekStatistics).Error
|
|
216
|
+ err = 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 log JOIN (Select d.user_org_id from (Select new_role.user_org_id from (Select count(*) as count,org_id as user_org_id from sgj_users.sgj_user_admin_role role where role.`user_type` = 2 OR role.`user_type` = 3 Group by role.org_id) new_role where new_role.count > 2) d JOIN (Select user_org_id from (Select count(*) as count,user_org_id from sgj_xt.xt_patients where status = 1 Group by user_org_id) new_patient where new_patient.count > 3) c On d.user_org_id = c.user_org_id) new_user_org ON new_user_org.user_org_id = log.org_id where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(ctime)) Group by date(from_unixtime(ctime))").Scan(&weekStatistics).Error
|
229
|
217
|
return
|
230
|
218
|
}
|
231
|
219
|
|
|
@@ -255,7 +243,7 @@ func GetThreeMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statist
|
255
|
243
|
|
256
|
244
|
//获取近3个月每个月的机构活跃总量
|
257
|
245
|
func GetThreeMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
|
258
|
|
- err = readDb.Raw("select DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times,count(DISTINCT(user_org_id)) as count From xt_dialysis_order where DATE_FORMAT(date(from_unixtime(created_time)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m') AND status = 1 group by times").Scan(&weekStatistics).Error
|
|
246
|
+ err = readUserDb.Raw(" Select count(DISTINCT(org_id)) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times from sgj_user_admin_login_log log JOIN (Select d.user_org_id from (Select new_role.user_org_id from (Select count(*) as count,org_id as user_org_id from sgj_users.sgj_user_admin_role role where role.`user_type` = 2 OR role.`user_type` = 3 Group by role.org_id) new_role where new_role.count > 2) d JOIN (Select user_org_id from (Select count(*) as count,user_org_id from sgj_xt.xt_patients where status = 1 Group by user_org_id) new_patient where new_patient.count > 3) c On d.user_org_id = c.user_org_id) new_user_org ON new_user_org.user_org_id = log.org_id where DATE_FORMAT(date(from_unixtime(ctime)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m') Group by times").Scan(&weekStatistics).Error
|
259
|
247
|
return
|
260
|
248
|
}
|
261
|
249
|
|
|
@@ -279,7 +267,7 @@ func GetSixMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statistic
|
279
|
267
|
|
280
|
268
|
//获取近半年每个月的机构活跃总量
|
281
|
269
|
func GetSixMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
|
282
|
|
- err = readDb.Raw("select DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times,count(DISTINCT(user_org_id)) as count From xt_dialysis_order where DATE_FORMAT(date(from_unixtime(created_time)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m') AND status = 1 group by times").Scan(&weekStatistics).Error
|
|
270
|
+ err = readUserDb.Raw(" Select count(DISTINCT(org_id)) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times from sgj_user_admin_login_log log JOIN (Select d.user_org_id from (Select new_role.user_org_id from (Select count(*) as count,org_id as user_org_id from sgj_users.sgj_user_admin_role role where role.`user_type` = 2 OR role.`user_type` = 3 Group by role.org_id) new_role where new_role.count > 2) d JOIN (Select user_org_id from (Select count(*) as count,user_org_id from sgj_xt.xt_patients where status = 1 Group by user_org_id) new_patient where new_patient.count > 3) c On d.user_org_id = c.user_org_id) new_user_org ON new_user_org.user_org_id = log.org_id where DATE_FORMAT(date(from_unixtime(ctime)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m') Group by times").Scan(&weekStatistics).Error
|
283
|
271
|
return
|
284
|
272
|
}
|
285
|
273
|
|
|
@@ -303,7 +291,7 @@ func GetYearActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, e
|
303
|
291
|
|
304
|
292
|
//获取近1年每个月的机构活跃总量
|
305
|
293
|
func GetYearActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
|
306
|
|
- err = readDb.Raw("select DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times,count(DISTINCT(user_org_id)) as count From xt_dialysis_order where DATE_FORMAT(date(from_unixtime(created_time)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') AND status = 1 group by times").Scan(&weekStatistics).Error
|
|
294
|
+ err = readUserDb.Raw(" Select count(DISTINCT(org_id)) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times from sgj_user_admin_login_log log JOIN (Select d.user_org_id from (Select new_role.user_org_id from (Select count(*) as count,org_id as user_org_id from sgj_users.sgj_user_admin_role role where role.`user_type` = 2 OR role.`user_type` = 3 Group by role.org_id) new_role where new_role.count > 2) d JOIN (Select user_org_id from (Select count(*) as count,user_org_id from sgj_xt.xt_patients where status = 1 Group by user_org_id) new_patient where new_patient.count > 3) c On d.user_org_id = c.user_org_id) new_user_org ON new_user_org.user_org_id = log.org_id where DATE_FORMAT(date(from_unixtime(ctime)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') Group by times").Scan(&weekStatistics).Error
|
307
|
295
|
return
|
308
|
296
|
}
|
309
|
297
|
|