|
@@ -9,20 +9,21 @@ import (
|
9
|
9
|
"time"
|
10
|
10
|
)
|
11
|
11
|
|
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){
|
|
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) {
|
13
|
13
|
offset := (page - 1) * limit
|
14
|
14
|
fmt.Println(offset)
|
15
|
15
|
db := readUserDb.Model(&models.Org{})
|
16
|
|
- if len(keyword) > 0{
|
|
16
|
+
|
|
17
|
+ if len(keyword) > 0 {
|
17
|
18
|
likeKey := "%" + keyword + "%"
|
18
|
|
- db = db.Where("contact_name LIKE ? Or org_name LIKE ? Or org_short_name Like ? ",likeKey,likeKey,likeKey)
|
19
|
|
- }else{
|
|
19
|
+ db = db.Where("contact_name LIKE ? Or org_name LIKE ? Or org_short_name Like ? ", likeKey, likeKey, likeKey)
|
|
20
|
+ } else {
|
20
|
21
|
|
21
|
22
|
switch active_status {
|
22
|
23
|
case 1:
|
23
|
24
|
now := time.Now()
|
24
|
25
|
zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
|
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())
|
|
26
|
+ 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())
|
26
|
27
|
break
|
27
|
28
|
case 2:
|
28
|
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 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 ")
|
|
@@ -39,7 +40,7 @@ func GetAllOrgList(active_status int64,depth_active_status int64,start_time int6
|
39
|
40
|
case 1:
|
40
|
41
|
now := time.Now()
|
41
|
42
|
zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
|
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_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
|
44
|
db = db.Joins("JOIN sgj_xt.xt_dialysis_order on sgj_xt.xt_dialysis_order.user_org_id = sgj_user_org.id AND DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m-%d') = DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m-%d') AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
|
44
|
45
|
|
45
|
46
|
break
|
|
@@ -59,16 +60,16 @@ func GetAllOrgList(active_status int64,depth_active_status int64,start_time int6
|
59
|
60
|
|
60
|
61
|
break
|
61
|
62
|
}
|
62
|
|
- if province > 0{
|
63
|
|
- db = db.Where("sgj_user_org.province = ?",province)
|
|
63
|
+ if province > 0 {
|
|
64
|
+ db = db.Where("sgj_user_org.province = ?", province)
|
64
|
65
|
}
|
65
|
66
|
|
66
|
|
- if city > 0{
|
67
|
|
- db = db.Where("sgj_user_org.city = ?",city)
|
|
67
|
+ if city > 0 {
|
|
68
|
+ db = db.Where("sgj_user_org.city = ?", city)
|
68
|
69
|
}
|
69
|
70
|
|
70
|
|
- if district > 0{
|
71
|
|
- db = db.Where("sgj_user_org.district = ?",district)
|
|
71
|
+ if district > 0 {
|
|
72
|
+ db = db.Where("sgj_user_org.district = ?", district)
|
72
|
73
|
}
|
73
|
74
|
|
74
|
75
|
if start_time != 0 {
|
|
@@ -78,37 +79,43 @@ func GetAllOrgList(active_status int64,depth_active_status int64,start_time int6
|
78
|
79
|
db = db.Where("sgj_user_org.ctime<=?", end_time)
|
79
|
80
|
}
|
80
|
81
|
|
|
82
|
+ if follow != 0 {
|
|
83
|
+ db = db.Joins("JOIN sgj_org_follow on sgj_org_follow.org_id = sgj_user_org.id AND sgj_org_follow.admin_user_id = ? AND sgj_org_follow.status = 1", follow)
|
|
84
|
+ }
|
|
85
|
+
|
81
|
86
|
}
|
82
|
|
- err = db.Where("sgj_user_org.status = 1").Preload("AdminUserLoginLog", func(db *gorm.DB) *gorm.DB {
|
|
87
|
+ err = db.Where("sgj_user_org.status = 1").Preload("OrgFollow", func(db *gorm.DB) *gorm.DB {
|
|
88
|
+ return db.Model(&models.OrgFollow{}).Where("status = 1").Preload("AdminAccount", "status = 1")
|
|
89
|
+ }).Preload("AdminUserLoginLog", func(db *gorm.DB) *gorm.DB {
|
83
|
90
|
return db.Model(&models.AdminUserLoginLog{}).Where("id = (SELECT max(id))")
|
84
|
91
|
}).Count(&total).Offset(offset).Limit(limit).Group("id").Find(&list).Error
|
85
|
92
|
return
|
86
|
93
|
}
|
87
|
94
|
|
88
|
|
-
|
89
|
|
-func GetOrgDetailInfo(org_id int64) (info models.Org, err error){
|
90
|
|
- err = readUserDb.Model(&models.Org{}).Where("id = ? AND status = 1",org_id).Preload("AdminUserLoginLog", func(db *gorm.DB) *gorm.DB {
|
|
95
|
+func GetOrgDetailInfo(org_id int64) (info models.Org, err error) {
|
|
96
|
+ err = readUserDb.Model(&models.Org{}).Where("id = ? AND status = 1", org_id).Preload("AdminUserLoginLog", func(db *gorm.DB) *gorm.DB {
|
91
|
97
|
return db.Model(&models.AdminUserLoginLog{}).Where("id = (SELECT max(id))")
|
92
|
|
- }).Preload("AdminUser","status = 1").Find(&info).Error
|
|
98
|
+ }).Preload("AdminUser", "status = 1").Find(&info).Error
|
93
|
99
|
return
|
94
|
100
|
}
|
95
|
101
|
|
96
|
|
-func GetDistrictsById(id int64)(district models.District, err error){
|
|
102
|
+func GetDistrictsById(id int64) (district models.District, err error) {
|
97
|
103
|
err = readUserDb.Model(&models.District{}).Where("id = ? ", id).First(&district).Error
|
98
|
104
|
return
|
99
|
105
|
}
|
100
|
106
|
|
101
|
|
-func GetAllOrgType()(types []*models.OrgType, err error){
|
|
107
|
+func GetAllOrgType() (types []*models.OrgType, err error) {
|
102
|
108
|
err = readUserDb.Model(&models.OrgType{}).Find(&types).Error
|
103
|
109
|
return
|
104
|
110
|
}
|
|
111
|
+
|
105
|
112
|
//设置今天和昨天的数据
|
106
|
|
-func GetOrgDialysisCount(statices_type int64, org_id int64, from int64,to int64) (count int64, err error){
|
|
113
|
+func GetOrgDialysisCount(statices_type int64, org_id int64, from int64, to int64) (count int64, err error) {
|
107
|
114
|
var counts int64
|
108
|
115
|
|
109
|
116
|
switch statices_type {
|
110
|
117
|
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()
|
|
118
|
+ 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
|
119
|
if err != nil {
|
113
|
120
|
return 0, err
|
114
|
121
|
}
|
|
@@ -117,7 +124,7 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64,to int64)
|
117
|
124
|
}
|
118
|
125
|
break
|
119
|
126
|
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()
|
|
127
|
+ 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
|
128
|
if err != nil {
|
122
|
129
|
return 0, err
|
123
|
130
|
}
|
|
@@ -126,7 +133,7 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64,to int64)
|
126
|
133
|
}
|
127
|
134
|
break
|
128
|
135
|
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()
|
|
136
|
+ 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
|
137
|
if err != nil {
|
131
|
138
|
return 0, err
|
132
|
139
|
}
|
|
@@ -135,7 +142,7 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64,to int64)
|
135
|
142
|
}
|
136
|
143
|
break
|
137
|
144
|
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()
|
|
145
|
+ 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
|
146
|
if err != nil {
|
140
|
147
|
return 0, err
|
141
|
148
|
}
|
|
@@ -143,8 +150,8 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64,to int64)
|
143
|
150
|
rows.Scan(&counts)
|
144
|
151
|
}
|
145
|
152
|
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()
|
|
153
|
+ case 5: //临时医嘱
|
|
154
|
+ 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
|
155
|
if err != nil {
|
149
|
156
|
return 0, err
|
150
|
157
|
}
|
|
@@ -153,7 +160,7 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64,to int64)
|
153
|
160
|
}
|
154
|
161
|
break
|
155
|
162
|
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()
|
|
163
|
+ 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
|
164
|
if err != nil {
|
158
|
165
|
return 0, err
|
159
|
166
|
}
|
|
@@ -162,7 +169,7 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64,to int64)
|
162
|
169
|
}
|
163
|
170
|
break
|
164
|
171
|
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()
|
|
172
|
+ 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
|
173
|
if err != nil {
|
167
|
174
|
return 0, err
|
168
|
175
|
}
|
|
@@ -172,7 +179,7 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64,to int64)
|
172
|
179
|
break
|
173
|
180
|
|
174
|
181
|
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()
|
|
182
|
+ 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
|
183
|
if err != nil {
|
177
|
184
|
return 0, err
|
178
|
185
|
}
|
|
@@ -181,7 +188,7 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64,to int64)
|
181
|
188
|
}
|
182
|
189
|
break
|
183
|
190
|
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()
|
|
191
|
+ 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
|
192
|
if err != nil {
|
186
|
193
|
return 0, err
|
187
|
194
|
}
|
|
@@ -190,7 +197,7 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64,to int64)
|
190
|
197
|
}
|
191
|
198
|
break
|
192
|
199
|
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()
|
|
200
|
+ 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
|
201
|
if err != nil {
|
195
|
202
|
return 0, err
|
196
|
203
|
}
|
|
@@ -199,7 +206,7 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64,to int64)
|
199
|
206
|
}
|
200
|
207
|
break
|
201
|
208
|
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()
|
|
209
|
+ 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
|
210
|
if err != nil {
|
204
|
211
|
return 0, err
|
205
|
212
|
}
|
|
@@ -208,7 +215,7 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64,to int64)
|
208
|
215
|
}
|
209
|
216
|
break
|
210
|
217
|
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()
|
|
218
|
+ 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
|
219
|
if err != nil {
|
213
|
220
|
return 0, err
|
214
|
221
|
}
|
|
@@ -221,7 +228,7 @@ func GetOrgDialysisCount(statices_type int64, org_id int64, from int64,to int64)
|
221
|
228
|
}
|
222
|
229
|
|
223
|
230
|
//获取近七天的数据
|
224
|
|
-func GetWeekOrgDialysisCount(statices_type int64,org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
|
|
231
|
+func GetWeekOrgDialysisCount(statices_type int64, org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
|
225
|
232
|
fmt.Println(statices_type)
|
226
|
233
|
|
227
|
234
|
switch statices_type {
|
|
@@ -230,253 +237,245 @@ func GetWeekOrgDialysisCount(statices_type int64,org_id int64) (weekStatistics [
|
230
|
237
|
|
231
|
238
|
break
|
232
|
239
|
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
|
|
240
|
+ 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
|
241
|
|
235
|
242
|
break
|
236
|
243
|
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
|
|
244
|
+ 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
|
245
|
|
239
|
246
|
break
|
240
|
247
|
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
|
|
248
|
+ 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
|
249
|
break
|
243
|
250
|
|
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
|
|
251
|
+ case 5: //临时医嘱
|
|
252
|
+ 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
|
253
|
|
247
|
254
|
break
|
248
|
255
|
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
|
|
256
|
+ 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
|
257
|
|
251
|
258
|
break
|
252
|
259
|
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
|
|
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 status = 1 AND user_org_id = ? AND (stage = 2 OR stage = 1) GROUP BY times", org_id).Scan(&weekStatistics).Error
|
254
|
261
|
break
|
255
|
262
|
|
256
|
263
|
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
|
|
264
|
+ 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
|
265
|
break
|
259
|
266
|
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
|
|
267
|
+ 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
|
268
|
|
262
|
269
|
break
|
263
|
270
|
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
|
|
271
|
+ 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
|
272
|
break
|
266
|
273
|
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
|
|
274
|
+ 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
|
275
|
break
|
269
|
276
|
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
|
|
277
|
+ 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
|
278
|
break
|
272
|
279
|
}
|
273
|
280
|
|
274
|
281
|
return
|
275
|
282
|
}
|
276
|
283
|
|
277
|
|
-
|
278
|
|
-
|
279
|
|
-func GetMonthOrgDialysisCount(statices_type int64,org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
|
|
284
|
+func GetMonthOrgDialysisCount(statices_type int64, org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
|
280
|
285
|
switch statices_type {
|
281
|
286
|
case 1: //病人管理
|
282
|
287
|
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
|
288
|
|
284
|
289
|
break
|
285
|
290
|
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
|
|
291
|
+ 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
|
292
|
|
288
|
293
|
break
|
289
|
294
|
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
|
|
295
|
+ 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
|
291
|
296
|
|
292
|
297
|
break
|
293
|
298
|
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
|
|
299
|
+ 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
|
300
|
break
|
296
|
301
|
|
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
|
|
302
|
+ case 5: //临时医嘱
|
|
303
|
+ 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
|
304
|
|
300
|
305
|
break
|
301
|
306
|
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
|
|
307
|
+ 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
|
308
|
|
304
|
309
|
break
|
305
|
310
|
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
|
|
311
|
+ 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
|
312
|
break
|
308
|
313
|
|
309
|
314
|
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
|
|
315
|
+ 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
|
316
|
break
|
312
|
317
|
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
|
|
318
|
+ 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
|
319
|
|
315
|
320
|
break
|
316
|
321
|
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
|
|
322
|
+ 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
|
323
|
break
|
319
|
324
|
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
|
|
325
|
+ 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
|
326
|
break
|
322
|
327
|
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
|
|
328
|
+ 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
|
329
|
break
|
325
|
330
|
}
|
326
|
331
|
return
|
327
|
332
|
}
|
328
|
333
|
|
329
|
|
-
|
330
|
|
-func GetThreeMonthOrgDialysisCount(statices_type int64,org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
|
|
334
|
+func GetThreeMonthOrgDialysisCount(statices_type int64, org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
|
331
|
335
|
switch statices_type {
|
332
|
336
|
case 1: //病人管理
|
333
|
337
|
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
|
338
|
|
335
|
339
|
break
|
336
|
340
|
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
|
|
341
|
+ 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
|
342
|
|
339
|
343
|
break
|
340
|
344
|
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
|
|
345
|
+ 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
|
346
|
|
343
|
347
|
break
|
344
|
348
|
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
|
|
349
|
+ 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
|
350
|
break
|
347
|
351
|
|
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
|
|
352
|
+ case 5: //临时医嘱
|
|
353
|
+ 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
|
354
|
|
351
|
355
|
break
|
352
|
356
|
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
|
|
357
|
+ 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
|
358
|
|
355
|
359
|
break
|
356
|
360
|
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
|
|
361
|
+ 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
|
362
|
break
|
359
|
363
|
|
360
|
364
|
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
|
|
365
|
+ 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
|
366
|
break
|
363
|
367
|
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
|
|
368
|
+ 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
|
369
|
|
366
|
370
|
break
|
367
|
371
|
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
|
|
372
|
+ 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
|
373
|
break
|
370
|
374
|
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
|
|
375
|
+ 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
|
376
|
break
|
373
|
377
|
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
|
|
378
|
+ 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
|
379
|
break
|
376
|
380
|
}
|
377
|
381
|
return
|
378
|
382
|
}
|
379
|
383
|
|
380
|
|
-
|
381
|
|
-
|
382
|
|
-func GetSixMonthOrgDialysisCount(statices_type int64,org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
|
|
384
|
+func GetSixMonthOrgDialysisCount(statices_type int64, org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
|
383
|
385
|
switch statices_type {
|
384
|
386
|
case 1: //病人管理
|
385
|
387
|
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
|
388
|
|
387
|
389
|
break
|
388
|
390
|
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
|
|
391
|
+ 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
|
392
|
|
391
|
393
|
break
|
392
|
394
|
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
|
|
395
|
+ 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
|
396
|
|
395
|
397
|
break
|
396
|
398
|
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
|
|
399
|
+ 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
|
400
|
break
|
399
|
401
|
|
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
|
+ case 5: //临时医嘱
|
|
403
|
+ 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
|
404
|
|
403
|
405
|
break
|
404
|
406
|
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
|
|
407
|
+ 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
|
408
|
|
407
|
409
|
break
|
408
|
410
|
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
|
|
411
|
+ 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
|
412
|
break
|
411
|
413
|
|
412
|
414
|
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
|
|
415
|
+ 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
|
416
|
break
|
415
|
417
|
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
|
|
418
|
+ 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
|
419
|
|
418
|
420
|
break
|
419
|
421
|
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
|
|
422
|
+ 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
|
423
|
break
|
422
|
424
|
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
|
|
425
|
+ 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
|
426
|
break
|
425
|
427
|
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
|
|
428
|
+ 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
|
429
|
break
|
428
|
430
|
}
|
429
|
431
|
return
|
430
|
432
|
}
|
431
|
433
|
|
432
|
|
-
|
433
|
|
-
|
434
|
|
-
|
435
|
|
-func GetYearOrgDialysisCount(statices_type int64,org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
|
|
434
|
+func GetYearOrgDialysisCount(statices_type int64, org_id int64) (weekStatistics []*admin_models.Statistics, err error) {
|
436
|
435
|
switch statices_type {
|
437
|
436
|
case 1: //病人管理
|
438
|
437
|
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
|
438
|
|
440
|
439
|
break
|
441
|
440
|
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
|
|
441
|
+ 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
|
442
|
|
444
|
443
|
break
|
445
|
444
|
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
|
|
445
|
+ 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
|
446
|
|
448
|
447
|
break
|
449
|
448
|
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
|
|
449
|
+ 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
|
450
|
break
|
452
|
451
|
|
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
|
|
452
|
+ case 5: //临时医嘱
|
|
453
|
+ 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
|
454
|
|
456
|
455
|
break
|
457
|
456
|
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
|
|
457
|
+ 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
|
458
|
|
460
|
459
|
break
|
461
|
460
|
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
|
|
461
|
+ 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
|
462
|
break
|
464
|
463
|
|
465
|
464
|
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
|
|
465
|
+ 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
|
466
|
break
|
468
|
467
|
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
|
|
468
|
+ 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
|
469
|
|
471
|
470
|
break
|
472
|
471
|
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
|
|
472
|
+ 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
|
473
|
break
|
475
|
474
|
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
|
|
475
|
+ 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
|
476
|
break
|
478
|
477
|
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
|
|
478
|
+ 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
|
479
|
break
|
481
|
480
|
}
|
482
|
481
|
return
|
|
@@ -486,3 +485,177 @@ func GetDistrictsByUpid(id int64) (dis []*models.District, err error) {
|
486
|
485
|
err = readUserDb.Model(&models.District{}).Where("upid=?", id).Find(&dis).Error
|
487
|
486
|
return
|
488
|
487
|
}
|
|
488
|
+
|
|
489
|
+func FindAllFollower() (follower []*admin_models.AdminAccount, err error) {
|
|
490
|
+ err = readUserDb.Model(&admin_models.AdminAccount{}).Where("status = 1 AND is_super_admin <> 1").Find(&follower).Error
|
|
491
|
+ return
|
|
492
|
+
|
|
493
|
+}
|
|
494
|
+
|
|
495
|
+func FindPatientById(id int64, page int64, limit int64) (patients []*models.Patients, err error, total int64) {
|
|
496
|
+ offset := (page - 1) * limit
|
|
497
|
+ db := readDb.Model(&models.Patients{}).Where("user_org_id=? AND status = 1", id)
|
|
498
|
+ db = db.Count(&total)
|
|
499
|
+ err = db.Offset(offset).Limit(limit).Find(&patients).Error
|
|
500
|
+ return
|
|
501
|
+}
|
|
502
|
+
|
|
503
|
+func GetAppTypeByOrgId(org_id int64) (appType models.OrgApp, err error) {
|
|
504
|
+ err = readUserDb.Model(&models.OrgApp{}).Where("app_type = 3 AND org_id = ?", org_id).First(&appType).Error
|
|
505
|
+ return
|
|
506
|
+}
|
|
507
|
+
|
|
508
|
+func GetRoles(orgID int64, appID int64, page int, count int) ([]*models.Role, int, error) {
|
|
509
|
+ var roles []*models.Role
|
|
510
|
+ var totalCount int
|
|
511
|
+ err := readUserDb.Model(&models.Role{}).
|
|
512
|
+ Where("org_id = ? AND app_id = ?", orgID, appID).
|
|
513
|
+ Count(&totalCount).
|
|
514
|
+ Order("ctime asc").Limit(count).Offset((page - 1) * count).
|
|
515
|
+ Find(&roles).
|
|
516
|
+ Error
|
|
517
|
+ if err != nil {
|
|
518
|
+ if err == gorm.ErrRecordNotFound {
|
|
519
|
+ return make([]*models.Role, 0), 0, nil
|
|
520
|
+ } else {
|
|
521
|
+ return nil, 0, err
|
|
522
|
+ }
|
|
523
|
+ }
|
|
524
|
+ return roles, totalCount, nil
|
|
525
|
+}
|
|
526
|
+
|
|
527
|
+func GetAdminUser(orgID int64, page int, count int) ([]*models.AdminUser, int, error) {
|
|
528
|
+ var roles []*models.AdminUser
|
|
529
|
+ var totalCount int
|
|
530
|
+ err := readUserDb.Model(&models.AdminUser{}).
|
|
531
|
+ Where("org_id = ? ", orgID).
|
|
532
|
+ Count(&totalCount).
|
|
533
|
+ Order("ctime asc").Limit(count).Offset((page - 1) * count).
|
|
534
|
+ Find(&roles).
|
|
535
|
+ Error
|
|
536
|
+ if err != nil {
|
|
537
|
+ if err == gorm.ErrRecordNotFound {
|
|
538
|
+ return make([]*models.AdminUser, 0), 0, nil
|
|
539
|
+ } else {
|
|
540
|
+ return nil, 0, err
|
|
541
|
+ }
|
|
542
|
+ }
|
|
543
|
+ return roles, totalCount, nil
|
|
544
|
+}
|
|
545
|
+
|
|
546
|
+type AdminUserManageViewModel struct {
|
|
547
|
+ AdminUserId int `gorm:"admin_user_id" json:"user_id"`
|
|
548
|
+ UserName string `gorm:"user_name" json:"user_name"`
|
|
549
|
+ RoleName string `gorm:"role_name" json:"role_name"`
|
|
550
|
+ UserTitle int `gorm:"user_title" json:"user_title"`
|
|
551
|
+ Ip string `gorm:"ip" json:"ip"`
|
|
552
|
+ Ctime int64 `gorm:"ctime" json:"last_login_time"`
|
|
553
|
+ Status int `gorm:"status" json:"status"`
|
|
554
|
+
|
|
555
|
+ // LastLoginTimeStr string `gorm:"-" json:"last_login_time_formatted"`
|
|
556
|
+ TitleName string `gorm:"-" json:"title_name"`
|
|
557
|
+}
|
|
558
|
+
|
|
559
|
+func GetAdminUsersAndLoginInfo(orgID int64, appID int64, page int64, count int64) ([]*AdminUserManageViewModel, int, error) {
|
|
560
|
+ if count <= 0 {
|
|
561
|
+ return []*AdminUserManageViewModel{}, 0, nil
|
|
562
|
+ }
|
|
563
|
+ if page < 1 {
|
|
564
|
+ page = 1
|
|
565
|
+ }
|
|
566
|
+ var viewModels []*AdminUserManageViewModel = make([]*AdminUserManageViewModel, 0)
|
|
567
|
+ rows, err := readUserDb.Raw("SELECT u_a_r.admin_user_id, u_a_r.user_name, u_r.role_name, u_a_r.user_title, u_l.ip, u_l.ctime, u_a_r.status FROM sgj_user_admin_role AS u_a_r INNER JOIN sgj_user_role AS u_r ON u_a_r.org_id = u_r.org_id AND u_a_r.app_id = u_r.app_id AND u_r.id = u_a_r.role_id LEFT JOIN (SELECT * FROM (SELECT admin_user_id, org_id, app_id, ip, ctime FROM sgj_user_admin_login_log WHERE org_id = ? AND app_id = ? ORDER BY ctime DESC) AS t GROUP BY admin_user_id) AS u_l ON u_a_r.org_id = u_l.org_id AND u_a_r.app_id = u_l.app_id AND u_a_r.admin_user_id = u_l.admin_user_id WHERE u_a_r.org_id = ? AND u_a_r.app_id = ? GROUP BY u_a_r.admin_user_id LIMIT ? OFFSET ?;", orgID, appID, orgID, appID, count, (page-1)*count).Rows()
|
|
568
|
+ defer rows.Close()
|
|
569
|
+ if err != nil {
|
|
570
|
+ if err == gorm.ErrRecordNotFound {
|
|
571
|
+ return viewModels, 0, nil
|
|
572
|
+ } else {
|
|
573
|
+ return nil, 0, err
|
|
574
|
+ }
|
|
575
|
+ }
|
|
576
|
+ for rows.Next() {
|
|
577
|
+ var viewModel AdminUserManageViewModel
|
|
578
|
+ readUserDb.ScanRows(rows, &viewModel)
|
|
579
|
+ title, _ := models.UserTitle[viewModel.UserTitle]
|
|
580
|
+ viewModel.TitleName = title
|
|
581
|
+ // if viewModel.Ctime == 0 {
|
|
582
|
+ // viewModel.LastLoginTimeStr = ""
|
|
583
|
+ // } else {
|
|
584
|
+ // loginTime := time.Unix(viewModel.Ctime, 0)
|
|
585
|
+ // viewModel.LastLoginTimeStr = loginTime.Format("2006-01-02 15:04")
|
|
586
|
+ // }
|
|
587
|
+ viewModels = append(viewModels, &viewModel)
|
|
588
|
+ }
|
|
589
|
+ total := 0
|
|
590
|
+ readUserDb.Table("sgj_user_admin_role as u_a_r").Joins("join sgj_user_role as u_r on u_r.org_id = u_a_r.org_id AND u_r.app_id = u_a_r.app_id AND u_r.id = u_a_r.role_id").Where("u_a_r.org_id = ? AND u_a_r.app_id = ?", orgID, appID).Count(&total)
|
|
591
|
+ return viewModels, total, nil
|
|
592
|
+}
|
|
593
|
+
|
|
594
|
+func GetAllValidDeviceZones(orgID int64) ([]*models.DeviceZone, error) {
|
|
595
|
+ var zones []*models.DeviceZone
|
|
596
|
+ err := readDb.Model(&models.DeviceZone{}).Where("org_id = ? AND status = 1", orgID).Find(&zones).Error
|
|
597
|
+ if err != nil {
|
|
598
|
+ return nil, err
|
|
599
|
+ }
|
|
600
|
+ return zones, nil
|
|
601
|
+}
|
|
602
|
+
|
|
603
|
+func GetAllValidDeviceGroups(orgID int64) ([]*models.DeviceGroup, error) {
|
|
604
|
+ var groups []*models.DeviceGroup
|
|
605
|
+ err := readDb.Model(&models.DeviceGroup{}).Where("org_id = ? AND status = 1", orgID).Find(&groups).Error
|
|
606
|
+ if err != nil {
|
|
607
|
+ return nil, err
|
|
608
|
+ }
|
|
609
|
+ return groups, nil
|
|
610
|
+}
|
|
611
|
+
|
|
612
|
+type DeviceNumberViewModel struct {
|
|
613
|
+ models.DeviceNumber
|
|
614
|
+ ZoneName string `gorm:"column:zone_name" json:"zone_name"`
|
|
615
|
+ GroupName string `gorm:"column:group_name" json:"group_name"`
|
|
616
|
+}
|
|
617
|
+
|
|
618
|
+func GetAllValidDeviceNumbers(orgID int64) ([]*DeviceNumberViewModel, error) {
|
|
619
|
+ var vms []*DeviceNumberViewModel = make([]*DeviceNumberViewModel, 0)
|
|
620
|
+ rows, err := readDb.Raw("SELECT n.*, z.name as zone_name, g.name as group_name FROM xt_device_number as n join xt_device_zone as z on z.id = n.zone_id join xt_device_group as g on g.id = n.group_id WHERE (n.org_id = ? AND n.status = 1)", orgID).Rows()
|
|
621
|
+ defer rows.Close()
|
|
622
|
+ if err != nil {
|
|
623
|
+ return nil, err
|
|
624
|
+ }
|
|
625
|
+ for rows.Next() {
|
|
626
|
+ var vm DeviceNumberViewModel
|
|
627
|
+ readDb.ScanRows(rows, &vm)
|
|
628
|
+ vms = append(vms, &vm)
|
|
629
|
+ }
|
|
630
|
+ return vms, nil
|
|
631
|
+}
|
|
632
|
+
|
|
633
|
+//func GetSpecialAdminUser(org_id int64, app_id int64, page int64, count int64) ([]*AdminUserManageViewModel, error){
|
|
634
|
+//
|
|
635
|
+// if count <= 0 {
|
|
636
|
+// return []*AdminUserManageViewModel{}, nil
|
|
637
|
+// }
|
|
638
|
+// if page < 1 {
|
|
639
|
+// page = 1
|
|
640
|
+// }
|
|
641
|
+// var viewModels []*AdminUserManageViewModel = make([]*AdminUserManageViewModel, 0)
|
|
642
|
+// rows, err := readUserDb.Raw("SELECT u_a_r.admin_user_id, u_a_r.user_name, u_r.role_name, u_a_r.user_title, u_l.ip, u_l.ctime, u_a_r.status FROM sgj_user_admin_role AS u_a_r INNER JOIN sgj_user_role AS u_r ON u_a_r.org_id = u_r.org_id AND u_a_r.app_id = u_r.app_id AND u_r.id = u_a_r.role_id LEFT JOIN (SELECT * FROM (SELECT admin_user_id, org_id, app_id, ip, ctime FROM sgj_user_admin_login_log WHERE org_id = ? AND app_id = ? ORDER BY ctime DESC) AS t GROUP BY admin_user_id) AS u_l ON u_a_r.org_id = u_l.org_id AND u_a_r.app_id = u_l.app_id AND u_a_r.admin_user_id = u_l.admin_user_id INNER JOIN sgj_xt.xt_admin_user_special_permission AS xt_p ON u_a_r.org_id = xt_p.org_id AND u_a_r.app_id = xt_p.app_id AND u_a_r.admin_user_id = xt_p.admin_user_id WHERE u_a_r.org_id = ? AND u_a_r.app_id = ? GROUP BY u_a_r.admin_user_id LIMIT ? OFFSET ?;", orgID, appID, orgID, appID, count, (page-1)*count).Rows()
|
|
643
|
+// defer rows.Close()
|
|
644
|
+// if err != nil {
|
|
645
|
+// if err == gorm.ErrRecordNotFound {
|
|
646
|
+// return viewModels, nil
|
|
647
|
+// } else {
|
|
648
|
+// return nil, err
|
|
649
|
+// }
|
|
650
|
+// }
|
|
651
|
+// for rows.Next() {
|
|
652
|
+// var viewModel AdminUserManageViewModel
|
|
653
|
+// readUserDb.ScanRows(rows, &viewModel)
|
|
654
|
+// title, _ := models.UserTitle[viewModel.UserTitle]
|
|
655
|
+// viewModel.TitleName = title
|
|
656
|
+// viewModels = append(viewModels, &viewModel)
|
|
657
|
+// }
|
|
658
|
+// return viewModels, nil
|
|
659
|
+//
|
|
660
|
+//
|
|
661
|
+//}
|