Explorar el Código

修改活跃机构统计

csx hace 4 años
padre
commit
6cacb2bcee

+ 2 - 0
controllers/admin_api_controllers/admin_api_router_register.go Ver fichero

@@ -47,6 +47,8 @@ func AdminAPIControllersRegisterRouters() {
47 47
 
48 48
 	beego.Router("/admin/api/org/list", &OrgAPIController{}, "get:GetOrgListOther")
49 49
 
50
+	beego.Router("/admin/api/activeorg/list", &OrgAPIController{}, "get:GetActiveOrgList")
51
+
50 52
 	//beego.Router("/admin/api/unfolloworg/list", &SystemApiController{}, "get:GetAllFollowOrg")
51 53
 
52 54
 }

+ 27 - 0
controllers/admin_api_controllers/org_api_controller.go Ver fichero

@@ -335,3 +335,30 @@ func (this *OrgAPIController) GetOrgListOther() {
335 335
 		})
336 336
 	}
337 337
 }
338
+
339
+func (this *OrgAPIController) GetActiveOrgList() {
340
+	range_data := this.GetString("range_data")
341
+	var rangeDate *time.Time
342
+	var parseDateErr error
343
+	var rangeTimeStamp int64
344
+
345
+	if len(range_data) > 0 {
346
+		rangeDate, parseDateErr = utils.ParseTimeStringToTime("2006-01-02", range_data)
347
+		if parseDateErr != nil {
348
+			this.ErrorLog("日期(%v)解析错误:%v", range_data, parseDateErr)
349
+			return
350
+		}
351
+		rangeTimeStamp = rangeDate.Unix()
352
+	} else {
353
+		rangeTimeStamp = 0
354
+	}
355
+	now := time.Now().Unix()
356
+	list, err := service.GetActiveOrgList(rangeTimeStamp, now)
357
+	if err != nil {
358
+	} else {
359
+		this.ServeSuccessJSON(map[string]interface{}{
360
+			"list": list,
361
+		})
362
+	}
363
+
364
+}

+ 19 - 31
service/admin_service.go Ver fichero

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

+ 12 - 0
service/org_service.go Ver fichero

@@ -700,3 +700,15 @@ func GetFollowOrgList(follow int64) (list []*models.Org, err error) {
700 700
 	return
701 701
 
702 702
 }
703
+
704
+type ActiveOrg struct {
705
+	OrgId   int64  `gorm:"org_id" json:"org_id"`
706
+	OrgName string `gorm:"org_name" json:"org_name"`
707
+}
708
+
709
+func GetActiveOrgList(from int64, to int64) (list []*ActiveOrg, err error) {
710
+	err = readUserDb.Raw("Select a.org_id as org_id, org.org_name as org_name from (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) a JOIN sgj_users.sgj_user_org org On a.org_id = org.id", from, to).Scan(&list).Error
711
+
712
+	return
713
+
714
+}