瀏覽代碼

机构功能相关接口

csx 4 年之前
父節點
當前提交
7dde6eb9c4

+ 1 - 1
conf/app.conf 查看文件

@@ -1,5 +1,5 @@
1 1
 appname = 血透
2
-httpport = 9629
2
+httpport = 9550
3 3
 runmode = dev
4 4
 
5 5
 copyrequestbody = true

+ 22 - 0
controllers/admin_api_controllers/admin_api_router_register.go 查看文件

@@ -20,4 +20,26 @@ func AdminAPIControllersRegisterRouters() {
20 20
 	beego.Router("/admin/api/orginfo", &OrgAPIController{}, "get:GetOrgInfo")
21 21
 	beego.Router("/admin/api/org/statistics", &OrgAPIController{}, "get:GetOrgDialysisOrderStatistics")
22 22
 
23
+	beego.Router("/admin/api/org/patient", &OrgAPIController{}, "get:GetOrgPatientList")
24
+	beego.Router("/admin/api/org/role", &OrgAPIController{}, "get:GetOrgRoleList")
25
+	beego.Router("/admin/api/org/adminuser", &OrgAPIController{}, "get:GetOrgAdminUser")
26
+	beego.Router("/admin/api/org/zones", &OrgAPIController{}, "get:GetOrgZones")
27
+	beego.Router("/admin/api/org/group", &OrgAPIController{}, "get:GetOrgGroup")
28
+	beego.Router("/admin/api/org/bed", &OrgAPIController{}, "get:GetOrgBed")
29
+
30
+	beego.Router("admin/api/system/user", &SystemApiController{}, "get:GetUserList")
31
+	beego.Router("/admin/api/user/create", &SystemApiController{}, "post:CreateAdminUser")
32
+	beego.Router("/admin/api/user/edit", &SystemApiController{}, "post:ModifyAdminUser")
33
+	beego.Router("/admin/api/user/delete", &SystemApiController{}, "post:DeleteAdminUser")
34
+
35
+	beego.Router("/admin/api/user/init", &SystemApiController{}, "get:GetUserInitData")
36
+	beego.Router("/admin/api/user/followorg", &SystemApiController{}, "get:GetFollowOrg")
37
+	beego.Router("/admin/api/follow", &SystemApiController{}, "post:PostFollowInfo")
38
+
39
+	beego.Router("/admin/api/follow/edit", &SystemApiController{}, "post:ModifyFollowInfo")
40
+	beego.Router("/admin/api/unfollow", &SystemApiController{}, "post:PostUnFollow")
41
+
42
+	beego.Router("/admin/api/user/get", &SystemApiController{}, "get:GetAdminUserById")
43
+	beego.Router("/admin/api/follow/cancel", &SystemApiController{}, "post:CancelFollowInfo")
44
+
23 45
 }

+ 0 - 3
controllers/admin_api_controllers/login_api_controller.go 查看文件

@@ -3,7 +3,6 @@ package admin_api_controllers
3 3
 import (
4 4
 	"XT_Admin_Api/enums"
5 5
 	"XT_Admin_Api/service"
6
-	"fmt"
7 6
 )
8 7
 
9 8
 type LoginAPIController struct {
@@ -27,8 +26,6 @@ func (this *LoginAPIController) LoginByPwd() {
27 26
 		return
28 27
 	}
29 28
 
30
-	fmt.Println(admin)
31
-
32 29
 	this.SetSession("admin_info", &AdminInfo{
33 30
 		Admin: admin,
34 31
 	})

+ 131 - 28
controllers/admin_api_controllers/org_api_controller.go 查看文件

@@ -14,14 +14,14 @@ type OrgAPIController struct {
14 14
 }
15 15
 
16 16
 func (this *OrgAPIController) GetOrgList() {
17
-	active_status,_ := this.GetInt64("active_status")
18
-	depth_active_status,_ := this.GetInt64("depth_active_status")
17
+	active_status, _ := this.GetInt64("active_status")
18
+	depth_active_status, _ := this.GetInt64("depth_active_status")
19 19
 	start_time := this.GetString("start_time")
20 20
 	end_time := this.GetString("end_time")
21
-	province,_ := this.GetInt64("province")
22
-	city,_ := this.GetInt64("city")
23
-	district,_ := this.GetInt64("district")
24
-	follow,_ := this.GetInt64("follow")
21
+	province, _ := this.GetInt64("province")
22
+	city, _ := this.GetInt64("city")
23
+	district, _ := this.GetInt64("district")
24
+	follow, _ := this.GetInt64("follow")
25 25
 	keyword := this.GetString("keyword")
26 26
 	page, _ := this.GetInt64("page", 0)
27 27
 	limit, _ := this.GetInt64("limit", 0)
@@ -57,13 +57,13 @@ func (this *OrgAPIController) GetOrgList() {
57 57
 
58 58
 	adminInfo := this.GetAdminInfo()
59 59
 	if adminInfo.Admin.IsSuperAdmin == 1 {
60
-		list, err, total := service.GetAllOrgList(active_status,depth_active_status,startTime,endTime,province,city,district,follow,keyword,page,limit)
60
+		list, err, total := service.GetAllOrgList(active_status, depth_active_status, startTime, endTime, province, city, district, follow, keyword, page, limit)
61 61
 		if err != nil {
62 62
 
63 63
 		} else {
64 64
 			this.ServeSuccessJSON(map[string]interface{}{
65
-				"list": list,
66
-				"total":total,
65
+				"list":  list,
66
+				"total": total,
67 67
 			})
68 68
 		}
69 69
 	} else {
@@ -72,7 +72,7 @@ func (this *OrgAPIController) GetOrgList() {
72 72
 }
73 73
 
74 74
 func (this *OrgAPIController) GetOrgInfo() {
75
-	org_id, _:=this.GetInt64("org_id",0)
75
+	org_id, _ := this.GetInt64("org_id", 0)
76 76
 	info, err := service.GetOrgDetailInfo(org_id)
77 77
 	province, _ := service.GetDistrictsById(info.Province)
78 78
 	city, _ := service.GetDistrictsById(info.City)
@@ -85,15 +85,15 @@ func (this *OrgAPIController) GetOrgInfo() {
85 85
 		return
86 86
 	} else {
87 87
 		this.ServeSuccessJSON(map[string]interface{}{
88
-			"info": info,
89
-			"area":province.Name+city.Name+district.Name,
90
-			"org_type":orgType,
88
+			"info":     info,
89
+			"area":     province.Name + city.Name + district.Name,
90
+			"org_type": orgType,
91 91
 		})
92 92
 	}
93 93
 }
94 94
 
95 95
 func (this *OrgAPIController) GetOrgDialysisOrderStatistics() {
96
-	org_id, _:=this.GetInt64("org_id",0)
96
+	org_id, _ := this.GetInt64("org_id", 0)
97 97
 	range_data := this.GetString("range_data")
98 98
 	range_type, _ := this.GetInt64("range_type")
99 99
 	statistics_type, _ := this.GetInt64("type")
@@ -101,12 +101,9 @@ func (this *OrgAPIController) GetOrgDialysisOrderStatistics() {
101 101
 	var parseDateErr error
102 102
 	var rangeTimeStamp int64
103 103
 
104
-
105
-
106
-
107 104
 	var orgDialysisOrderStatistics []*admin_models.Statistics
108 105
 
109
-	switch range_type{
106
+	switch range_type {
110 107
 	case 1: //今天
111 108
 		if len(range_data) > 0 {
112 109
 			rangeDate, parseDateErr = utils.ParseTimeStringToTime("2006-01-02", range_data)
@@ -119,7 +116,7 @@ func (this *OrgAPIController) GetOrgDialysisOrderStatistics() {
119 116
 			rangeTimeStamp = 0
120 117
 		}
121 118
 		now := time.Now().Unix()
122
-		count , err := service.GetOrgDialysisCount(statistics_type,org_id,rangeTimeStamp,now)
119
+		count, err := service.GetOrgDialysisCount(statistics_type, org_id, rangeTimeStamp, now)
123 120
 		if err != nil {
124 121
 			this.ErrorLog("错误:%v", err)
125 122
 			return
@@ -130,7 +127,7 @@ func (this *OrgAPIController) GetOrgDialysisOrderStatistics() {
130 127
 			})
131 128
 		}
132 129
 		break
133
-	case 2:  //昨天
130
+	case 2: //昨天
134 131
 		if len(range_data) > 0 {
135 132
 			rangeDate, parseDateErr = utils.ParseTimeStringToTime("2006-01-02", range_data)
136 133
 			if parseDateErr != nil {
@@ -142,7 +139,7 @@ func (this *OrgAPIController) GetOrgDialysisOrderStatistics() {
142 139
 			rangeTimeStamp = 0
143 140
 		}
144 141
 		now := time.Now().Unix()
145
-		count , err := service.GetOrgDialysisCount(statistics_type,org_id,rangeTimeStamp,now)
142
+		count, err := service.GetOrgDialysisCount(statistics_type, org_id, rangeTimeStamp, now)
146 143
 		if err != nil {
147 144
 			this.ErrorLog("错误:%v", err)
148 145
 			return
@@ -153,7 +150,7 @@ func (this *OrgAPIController) GetOrgDialysisOrderStatistics() {
153 150
 			})
154 151
 		}
155 152
 		break
156
-	case 3://一周
153
+	case 3: //一周
157 154
 		var err error
158 155
 		orgDialysisOrderStatistics, err = service.GetWeekOrgDialysisCount(statistics_type, org_id)
159 156
 		if err != nil {
@@ -165,7 +162,7 @@ func (this *OrgAPIController) GetOrgDialysisOrderStatistics() {
165 162
 			})
166 163
 		}
167 164
 		break
168
-	case 4://一个月
165
+	case 4: //一个月
169 166
 		var err error
170 167
 		orgDialysisOrderStatistics, err = service.GetMonthOrgDialysisCount(statistics_type, org_id)
171 168
 		if err != nil {
@@ -177,7 +174,7 @@ func (this *OrgAPIController) GetOrgDialysisOrderStatistics() {
177 174
 			})
178 175
 		}
179 176
 		break
180
-	case 5://三个月
177
+	case 5: //三个月
181 178
 		var err error
182 179
 		orgDialysisOrderStatistics, err = service.GetThreeMonthOrgDialysisCount(statistics_type, org_id)
183 180
 		if err != nil {
@@ -189,7 +186,7 @@ func (this *OrgAPIController) GetOrgDialysisOrderStatistics() {
189 186
 			})
190 187
 		}
191 188
 		break
192
-	case 6://半年
189
+	case 6: //半年
193 190
 		var err error
194 191
 		orgDialysisOrderStatistics, err = service.GetSixMonthOrgDialysisCount(statistics_type, org_id)
195 192
 		if err != nil {
@@ -201,7 +198,7 @@ func (this *OrgAPIController) GetOrgDialysisOrderStatistics() {
201 198
 			})
202 199
 		}
203 200
 		break
204
-	case 7://一年
201
+	case 7: //一年
205 202
 		var err error
206 203
 		orgDialysisOrderStatistics, err = service.GetYearOrgDialysisCount(statistics_type, org_id)
207 204
 		if err != nil {
@@ -225,10 +222,116 @@ func (c *OrgAPIController) GetDistrictsByUpid() {
225 222
 	return
226 223
 }
227 224
 
228
-
229
-func (this *OrgAPIController)GetInitData(){
225
+func (this *OrgAPIController) GetInitData() {
230 226
 	provinces, _ := service.GetDistrictsByUpid(0)
227
+	follower, _ := service.FindAllFollower()
228
+
231 229
 	this.ServeSuccessJSON(map[string]interface{}{
232 230
 		"provinces": provinces,
231
+		"follower":  follower,
232
+	})
233
+}
234
+
235
+func (this *OrgAPIController) GetOrgPatientList() {
236
+	org_id, _ := this.GetInt64("org_id", 0)
237
+	page, _ := this.GetInt64("page", 0)
238
+	limit, _ := this.GetInt64("limit", 0)
239
+	if page <= 0 {
240
+		page = 1
241
+	}
242
+	if limit <= 0 {
243
+		limit = 7
244
+	}
245
+
246
+	patients, _, total := service.FindPatientById(org_id, page, limit)
247
+	this.ServeSuccessJSON(map[string]interface{}{
248
+		"patients": patients,
249
+		"total":    total,
250
+	})
251
+
252
+}
253
+func (this *OrgAPIController) GetOrgRoleList() {
254
+	org_id, _ := this.GetInt64("org_id")
255
+	page, _ := this.GetInt("page")
256
+	if page <= 0 {
257
+		page = 1
258
+	}
259
+	appType, _ := service.GetAppTypeByOrgId(org_id)
260
+	roles, total, getRoleErr := service.GetRoles(org_id, appType.Id, page, 10)
261
+	if getRoleErr != nil {
262
+		//beego.Error("获取角色列表失败:", getRoleErr)
263
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
264
+	} else {
265
+		this.ServeSuccessJSON(map[string]interface{}{
266
+			"roles":       roles,
267
+			"total_count": total,
268
+		})
269
+	}
270
+}
271
+func (this *OrgAPIController) GetOrgAdminUser() {
272
+	org_id, _ := this.GetInt64("org_id", 0)
273
+	page, _ := this.GetInt64("page", 0)
274
+	limit, _ := this.GetInt64("limit", 0)
275
+	if page <= 0 {
276
+		page = 1
277
+	}
278
+	if limit <= 0 {
279
+		limit = 7
280
+	}
281
+	appType, _ := service.GetAppTypeByOrgId(org_id)
282
+
283
+	viewModels, total, getAdminsErr := service.GetAdminUsersAndLoginInfo(org_id, appType.Id, page, 10)
284
+
285
+	if getAdminsErr != nil {
286
+		//beego.Error("获取管理员列表失败:", getAdminsErr)
287
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
288
+	} else {
289
+		this.ServeSuccessJSON(map[string]interface{}{
290
+			"admins":      viewModels,
291
+			"total_count": total,
292
+		})
293
+	}
294
+
295
+}
296
+
297
+func (this *OrgAPIController) GetOrgZones() {
298
+	org_id, _ := this.GetInt64("org_id", 0)
299
+
300
+	zones, getZonesErr := service.GetAllValidDeviceZones(org_id)
301
+	if getZonesErr != nil {
302
+		this.ErrorLog("获取设备分区列表失败:%v", getZonesErr)
303
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
304
+		return
305
+	}
306
+	this.ServeSuccessJSON(map[string]interface{}{
307
+		"zones": zones,
308
+	})
309
+
310
+}
311
+func (this *OrgAPIController) GetOrgGroup() {
312
+	org_id, _ := this.GetInt64("org_id", 0)
313
+
314
+	groups, getGroupsErr := service.GetAllValidDeviceGroups(org_id)
315
+	if getGroupsErr != nil {
316
+		//beego.Error("获取设备分组列表失败:", getGroupsErr)
317
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
318
+		return
319
+	}
320
+	this.ServeSuccessJSON(map[string]interface{}{
321
+		"groups": groups,
322
+	})
323
+}
324
+
325
+func (this *OrgAPIController) GetOrgBed() {
326
+	org_id, _ := this.GetInt64("org_id", 0)
327
+
328
+	numbers, getNumbersErr := service.GetAllValidDeviceNumbers(org_id)
329
+	if getNumbersErr != nil {
330
+		//beego.Error("获取机号列表失败:", getNumbersErr)
331
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
332
+		return
333
+	}
334
+	this.ServeSuccessJSON(map[string]interface{}{
335
+		"numbers": numbers,
233 336
 	})
234 337
 }

+ 356 - 0
controllers/admin_api_controllers/system_api_controller.go 查看文件

@@ -0,0 +1,356 @@
1
+package admin_api_controllers
2
+
3
+import (
4
+	"XT_Admin_Api/enums"
5
+	"XT_Admin_Api/models"
6
+	"XT_Admin_Api/models/admin_models"
7
+	"XT_Admin_Api/service"
8
+	"XT_Admin_Api/utils"
9
+	"encoding/json"
10
+	"github.com/jinzhu/gorm"
11
+	"reflect"
12
+	"time"
13
+)
14
+
15
+type SystemApiController struct {
16
+	AdminBaseAPIAuthController
17
+}
18
+
19
+func (this *SystemApiController) GetUserList() {
20
+	list, _ := service.GetAllAdmin()
21
+	this.ServeSuccessJSON(map[string]interface{}{
22
+		"list": list,
23
+	})
24
+
25
+}
26
+
27
+func (this *SystemApiController) CreateAdminUser() {
28
+	name := this.GetString("name")
29
+	mobile := this.GetString("mobile")
30
+	password := this.GetString("password")
31
+	admin := &admin_models.AdminAccount{
32
+		Account:      mobile,
33
+		Pwd:          password,
34
+		Name:         name,
35
+		Status:       1,
36
+		IsSuperAdmin: 2,
37
+		Ctime:        time.Now().Unix(),
38
+		Mtime:        time.Now().Unix(),
39
+	}
40
+	admins, _ := service.FindUserInfoByAccount(mobile)
41
+	if admins.ID > 0 {
42
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNameException)
43
+		return
44
+
45
+	}
46
+
47
+	err := service.CreateAdmin(admin)
48
+	if err == nil {
49
+		this.ServeSuccessJSON(map[string]interface{}{
50
+			"admin": admin,
51
+		})
52
+	}
53
+}
54
+
55
+func (this *SystemApiController) ModifyAdminUser() {
56
+	id, _ := this.GetInt64("id")
57
+	name := this.GetString("name")
58
+	mobile := this.GetString("mobile")
59
+	password := this.GetString("password")
60
+	status, _ := this.GetInt64("status")
61
+
62
+	admins, _ := service.FindAdminById(id)
63
+
64
+	admin := &admin_models.AdminAccount{
65
+		ID:           admins.ID,
66
+		Account:      mobile,
67
+		Pwd:          password,
68
+		Name:         name,
69
+		Status:       status,
70
+		IsSuperAdmin: 2,
71
+		Ctime:        admins.Ctime,
72
+		Mtime:        time.Now().Unix(),
73
+	}
74
+
75
+	info, _ := service.FindUserInfoByAccount(mobile)
76
+	if info.ID > 0 {
77
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNameException)
78
+		return
79
+
80
+	}
81
+
82
+	err := service.UpdateAdmin(admin)
83
+	if err == nil {
84
+		this.ServeSuccessJSON(map[string]interface{}{
85
+			"admin": admin,
86
+		})
87
+	}
88
+}
89
+
90
+func (this *SystemApiController) DeleteAdminUser() {
91
+	id, _ := this.GetInt64("id")
92
+	err := service.DeleteAdmin(id)
93
+	if err == nil {
94
+		this.ServeSuccessJSON(map[string]interface{}{
95
+			"msg": "删除成功",
96
+		})
97
+	}
98
+}
99
+
100
+func (this *SystemApiController) GetUserInitData() {
101
+	org, err := service.FindAllOrg()
102
+	if err == nil {
103
+		this.ServeSuccessJSON(map[string]interface{}{
104
+			"org": org,
105
+		})
106
+	}
107
+}
108
+
109
+func (this *SystemApiController) GetFollowOrg() {
110
+	id, _ := this.GetInt64("admin_user_id")
111
+	FollowOrgs, err := service.FindFollowOrg(id)
112
+	unFollow, _ := service.FindUnFollowOrgByIds(id)
113
+
114
+	if err == nil {
115
+		this.ServeSuccessJSON(map[string]interface{}{
116
+			"follows":  FollowOrgs,
117
+			"unFollow": unFollow,
118
+		})
119
+	}
120
+}
121
+
122
+func (this *SystemApiController) GetAdminUserById() {
123
+	id, _ := this.GetInt64("id")
124
+	account, err := service.FindAdminById(id)
125
+	if err == nil {
126
+		this.ServeSuccessJSON(map[string]interface{}{
127
+			"account": account,
128
+		})
129
+	}
130
+}
131
+
132
+func (this *SystemApiController) PostFollowInfo() {
133
+	time := time.Now().Unix()
134
+
135
+	var orgFollow []*models.OrgFollow
136
+
137
+	dataBody := make(map[string]interface{}, 0)
138
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
139
+	if err != nil {
140
+		utils.ErrorLog(err.Error())
141
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
142
+		return
143
+	}
144
+
145
+	if dataBody["Follow"] != nil && reflect.TypeOf(dataBody["Follow"]).String() == "[]interface {}" {
146
+		thisFollow, _ := dataBody["Follow"].([]interface{})
147
+		if len(thisFollow) > 0 {
148
+			for _, item := range thisFollow {
149
+				items := item.(map[string]interface{})
150
+				if items["org_id"] == nil || reflect.TypeOf(items["org_id"]).String() != "float64" {
151
+					utils.ErrorLog("org_id")
152
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
153
+					return
154
+				}
155
+				org_id := int64(items["org_id"].(float64))
156
+
157
+				if items["admin_user_id"] == nil || reflect.TypeOf(items["admin_user_id"]).String() != "float64" {
158
+					utils.ErrorLog("admin_user_id")
159
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
160
+					return
161
+				}
162
+				admin_user_id := int64(items["admin_user_id"].(float64))
163
+				follow := &models.OrgFollow{
164
+					Mtime:       time,
165
+					Status:      1,
166
+					Ctime:       time,
167
+					OrgId:       org_id,
168
+					AdminUserId: admin_user_id,
169
+				}
170
+				orgFollow = append(orgFollow, follow)
171
+			}
172
+		}
173
+	}
174
+
175
+	//防止数据冗余,先查出之前被删的数据是否存在,存在则直接改变删除状态,不插入新数据
176
+	for index, follow := range orgFollow {
177
+		info, err := service.FindFollowRecordByID(follow)
178
+
179
+		if err == nil { //存在,则修改删除状态
180
+			orgFollow = append(orgFollow[:index], orgFollow[index+1:]...)
181
+			if info.Status == 0 {
182
+				follow := &models.OrgFollow{
183
+					ID:          info.ID,
184
+					Mtime:       info.Mtime,
185
+					Status:      1,
186
+					Ctime:       info.Ctime,
187
+					OrgId:       info.OrgId,
188
+					AdminUserId: info.AdminUserId,
189
+				}
190
+				service.UpdateFollow(follow)
191
+			}
192
+
193
+		}
194
+	}
195
+
196
+	if len(orgFollow) > 0 {
197
+		errs := service.CreateFollowInfo(orgFollow)
198
+		if errs == nil {
199
+			this.ServeSuccessJSON(map[string]interface{}{
200
+				"msg": "提交成功",
201
+			})
202
+
203
+		}
204
+	} else {
205
+		this.ServeSuccessJSON(map[string]interface{}{
206
+			"msg": "提交成功",
207
+		})
208
+	}
209
+
210
+}
211
+
212
+func (this *SystemApiController) CancelFollowInfo() {
213
+	time := time.Now().Unix()
214
+
215
+	var orgFollow []*models.OrgFollow
216
+
217
+	dataBody := make(map[string]interface{}, 0)
218
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
219
+	if err != nil {
220
+		utils.ErrorLog(err.Error())
221
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
222
+		return
223
+	}
224
+
225
+	if dataBody["Follow"] != nil && reflect.TypeOf(dataBody["Follow"]).String() == "[]interface {}" {
226
+		thisFollow, _ := dataBody["Follow"].([]interface{})
227
+		if len(thisFollow) > 0 {
228
+			for _, item := range thisFollow {
229
+				items := item.(map[string]interface{})
230
+				if items["org_id"] == nil || reflect.TypeOf(items["org_id"]).String() != "float64" {
231
+					utils.ErrorLog("org_id")
232
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
233
+					return
234
+				}
235
+				org_id := int64(items["org_id"].(float64))
236
+
237
+				if items["follow_id"] == nil || reflect.TypeOf(items["follow_id"]).String() != "float64" {
238
+					utils.ErrorLog("follow_id")
239
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
240
+					return
241
+				}
242
+				follow_id := int64(items["follow_id"].(float64))
243
+
244
+				if items["admin_user_id"] == nil || reflect.TypeOf(items["admin_user_id"]).String() != "float64" {
245
+					utils.ErrorLog("admin_user_id")
246
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
247
+					return
248
+				}
249
+				admin_user_id := int64(items["admin_user_id"].(float64))
250
+				follow := &models.OrgFollow{
251
+					ID:          follow_id,
252
+					Mtime:       time,
253
+					Status:      0,
254
+					Ctime:       time,
255
+					OrgId:       org_id,
256
+					AdminUserId: admin_user_id,
257
+				}
258
+				orgFollow = append(orgFollow, follow)
259
+			}
260
+		}
261
+	}
262
+	for _, follow := range orgFollow {
263
+		service.UpdateFollow(follow)
264
+	}
265
+	this.ServeSuccessJSON(map[string]interface{}{
266
+		"follow": orgFollow,
267
+	})
268
+
269
+}
270
+
271
+func (this *SystemApiController) PostUnFollow() {
272
+	org_id, _ := this.GetInt64("org_id")
273
+	admin_user_id, _ := this.GetInt64("admin_user_id")
274
+
275
+	info, _ := service.FindFollowInfoById(org_id, admin_user_id)
276
+	follow := &models.OrgFollow{
277
+		ID:          info.ID,
278
+		Mtime:       time.Now().Unix(),
279
+		Status:      0,
280
+		Ctime:       info.Ctime,
281
+		OrgId:       org_id,
282
+		AdminUserId: info.AdminUserId,
283
+	}
284
+	service.UpdateFollow(follow)
285
+}
286
+
287
+func (this *SystemApiController) ModifyFollowInfo() {
288
+	org_id, _ := this.GetInt64("org_id")
289
+	time := time.Now().Unix()
290
+
291
+	var orgFollow []*models.OrgFollow
292
+
293
+	dataBody := make(map[string]interface{}, 0)
294
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
295
+	if err != nil {
296
+		utils.ErrorLog(err.Error())
297
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
298
+		return
299
+	}
300
+
301
+	if dataBody["Follow"] != nil && reflect.TypeOf(dataBody["Follow"]).String() == "[]interface {}" {
302
+		thisFollow, _ := dataBody["Follow"].([]interface{})
303
+		if len(thisFollow) > 0 {
304
+			for _, item := range thisFollow {
305
+				items := item.(map[string]interface{})
306
+				if items["admin_user_id"] == nil || reflect.TypeOf(items["admin_user_id"]).String() != "float64" {
307
+					utils.ErrorLog("admin_user_id")
308
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
309
+					return
310
+				}
311
+				admin_user_id := int64(items["admin_user_id"].(float64))
312
+				follow := &models.OrgFollow{
313
+					Mtime:       time,
314
+					Status:      1,
315
+					Ctime:       time,
316
+					OrgId:       org_id,
317
+					AdminUserId: admin_user_id,
318
+				}
319
+				orgFollow = append(orgFollow, follow)
320
+			}
321
+		}
322
+	}
323
+
324
+	//防止数据冗余,先查出之前被删的数据是否存在,存在则直接改变删除状态,不插入新数据
325
+	for index, follow := range orgFollow {
326
+		info, err := service.FindFollowRecordByID(follow)
327
+		if err == gorm.ErrRecordNotFound { //不存在,过滤掉该数据
328
+			orgFollow = append(orgFollow[:index], orgFollow[index+1:]...)
329
+		} else if err == nil { //存在,则修改删除状态
330
+			follow := &models.OrgFollow{
331
+				ID:          info.ID,
332
+				Mtime:       info.Mtime,
333
+				Status:      1,
334
+				Ctime:       info.Ctime,
335
+				OrgId:       info.OrgId,
336
+				AdminUserId: info.AdminUserId,
337
+			}
338
+			service.UpdateFollow(follow)
339
+		}
340
+	}
341
+
342
+	if len(orgFollow) > 0 {
343
+		errs := service.CreateFollowInfo(orgFollow)
344
+		if errs == nil {
345
+			this.ServeSuccessJSON(map[string]interface{}{
346
+				"msg": "提交成功",
347
+			})
348
+
349
+		}
350
+	} else {
351
+		this.ServeSuccessJSON(map[string]interface{}{
352
+			"msg": "提交成功",
353
+		})
354
+	}
355
+
356
+}

+ 8 - 6
enums/error_code.go 查看文件

@@ -159,9 +159,9 @@ const ( // ErrorCode
159 159
 	ErrorCodePrescriptionPermissionDeniedModify = 200020
160 160
 
161 161
 	ErrorCodeAdvicePermissionDeniedModify = 200021
162
-	ErrorCodePrescriptionException    = 200022
163
-
162
+	ErrorCodePrescriptionException        = 200022
164 163
 
164
+	ErrorCodeNameException = 200023
165 165
 )
166 166
 
167 167
 var ErrCodeMsgs = map[int]string{
@@ -317,12 +317,14 @@ var ErrCodeMsgs = map[int]string{
317 317
 
318 318
 	ErrorCodeDeleteDealerWrong:       "该经销商所属商品已入库无法删除",
319 319
 	ErrorCodeDeleteManufacturerWrong: "该厂商所属商品已入库无法删除",
320
-	ErrorCodeGoodTypeNameExistError: "该商品类型名字已存在",
321
-	ErrorCodeGoodInfoNameExistError: "该规格名称名字已存在",
320
+	ErrorCodeGoodTypeNameExistError:  "该商品类型名字已存在",
321
+	ErrorCodeGoodInfoNameExistError:  "该规格名称名字已存在",
322 322
 
323 323
 	ErrorCodePrescriptionPermissionDeniedModify: "您没有权限修改透析处方数据",
324
-	ErrorCodeAdvicePermissionDeniedModify: "您没有权限添加医嘱",
325
-	ErrorCodePrescriptionException: "上机失败,请先开处方",
324
+	ErrorCodeAdvicePermissionDeniedModify:       "您没有权限添加医嘱",
325
+	ErrorCodePrescriptionException:              "上机失败,请先开处方",
326
+
327
+	ErrorCodeNameException: "账号已经存在",
326 328
 }
327 329
 
328 330
 type SGJError struct {

+ 7 - 6
models/admin_models/admin_models.go 查看文件

@@ -3,13 +3,14 @@
3 3
 package admin_models
4 4
 
5 5
 type AdminAccount struct {
6
-	Id           int    `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"`
7
-	Account      string `json:"account"`
8
-	Pwd          string `json:"-"`
9
-	Status       int8   `json:"-"`                     // 状态 0.无效 1.有效
10
-	CreateTime   int64  `gorm:"column:ctime" json:"-"` // 创建时间
11
-	ModifyTime   int64  `gorm:"column:mtime" json:"-"` // 修改时间
6
+	ID           int64  `gorm:"column:id" json:"id"`
7
+	Account      string `gorm:"column:account" json:"account"`
8
+	Pwd          string `gorm:"column:pwd" json:"pwd"`
9
+	Status       int64  `gorm:"column:status" json:"status"`
10
+	Ctime        int64  `gorm:"column:ctime" json:"ctime"`
11
+	Mtime        int64  `gorm:"column:mtime" json:"mtime"`
12 12
 	IsSuperAdmin int64  `gorm:"column:is_super_admin" json:"is_super_admin"`
13
+	Name         string `gorm:"column:name" json:"name"`
13 14
 }
14 15
 
15 16
 func (AdminAccount) TableName() string {

+ 1 - 0
models/admin_user_models.go 查看文件

@@ -8,6 +8,7 @@ type AdminUser struct {
8 8
 	Status       int8   `json:"status"`                                      // 状态 0.无效 1.有效
9 9
 	CreateTime   int64  `gorm:"column:ctime" json:"ctime"`                   // 创建时间
10 10
 	ModifyTime   int64  `gorm:"column:mtime" json:"mtime"`                   // 修改时间
11
+	Name         string `gorm:"column:name" json:"name"`
11 12
 }
12 13
 
13 14
 func (AdminUser) TableName() string {

+ 59 - 0
models/org_models.go 查看文件

@@ -1,5 +1,7 @@
1 1
 package models
2 2
 
3
+import "XT_Admin_Api/models/admin_models"
4
+
3 5
 type Org struct {
4 6
 	Id                int64             `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"` // 机构 ID
5 7
 	Creator           int64             `json:"creator"`                              // 创建者,即管理员用户的 id
@@ -28,6 +30,7 @@ type Org struct {
28 30
 	OrgGallery        []*OrgGallery     `gorm:"ForeignKey:OrgId" json:"org_gallery"`
29 31
 	AdminUserLoginLog AdminUserLoginLog `gorm:"ForeignKey:OrgId" json:"log"`
30 32
 	AdminUser         AdminUser         `gorm:"ForeignKey:Id" json:"admin"`
33
+	OrgFollow         []*OrgFollow      `gorm:"ForeignKey:OrgId" json:"follow"`
31 34
 }
32 35
 
33 36
 func (Org) TableName() string {
@@ -136,3 +139,59 @@ type UserOrgType struct {
136 139
 func (UserOrgType) TableName() string {
137 140
 	return "sgj_user_org_type"
138 141
 }
142
+
143
+type DeviceZone struct {
144
+	ID         int64  `gorm:"column:id" json:"id"`
145
+	OrgID      int64  `gorm:"column:org_id" json:"-"`
146
+	Name       string `json:"name"`
147
+	Type       int    `json:"type"`
148
+	Status     int8   `json:"-"`
149
+	CreateTime int64  `gorm:"column:ctime" json:"-"`
150
+	ModifyTime int64  `gorm:"column:mtime" json:"-"`
151
+}
152
+
153
+func (DeviceZone) TableName() string {
154
+	return "xt_device_zone"
155
+}
156
+
157
+type DeviceGroup struct {
158
+	ID         int64  `gorm:"column:id" json:"id"`
159
+	OrgID      int64  `gorm:"column:org_id" json:"-"`
160
+	Name       string `json:"name"`
161
+	Status     int8   `json:"-"`
162
+	CreateTime int64  `gorm:"column:ctime" json:"-"`
163
+	ModifyTime int64  `gorm:"column:mtime" json:"-"`
164
+}
165
+
166
+func (DeviceGroup) TableName() string {
167
+	return "xt_device_group"
168
+}
169
+
170
+type DeviceNumber struct {
171
+	ID         int64  `gorm:"column:id" json:"id"`
172
+	OrgID      int64  `gorm:"column:org_id" json:"-"`
173
+	Number     string `json:"number"`
174
+	GroupID    int64  `gorm:"column:group_id" json:"group_id"`
175
+	ZoneID     int64  `gorm:"column:zone_id" json:"zone_id"`
176
+	Status     int8   `json:"-"`
177
+	CreateTime int64  `gorm:"column:ctime" json:"-"`
178
+	ModifyTime int64  `gorm:"column:mtime" json:"-"`
179
+}
180
+
181
+func (DeviceNumber) TableName() string {
182
+	return "xt_device_number"
183
+}
184
+
185
+type OrgFollow struct {
186
+	ID           int64                     `gorm:"column:id" json:"id"`
187
+	OrgId        int64                     `gorm:"column:org_id" json:"org_id"`
188
+	AdminUserId  int64                     `gorm:"column:admin_user_id" json:"admin_user_id"`
189
+	Ctime        int64                     `gorm:"column:ctime" json:"ctime"`
190
+	Mtime        int64                     `gorm:"column:mtime" json:"mtime"`
191
+	Status       int64                     `gorm:"column:status" json:"status"`
192
+	AdminAccount admin_models.AdminAccount `gorm:"ForeignKey:ID;AssociationForeignKey:AdminUserId" json:"account"`
193
+}
194
+
195
+func (OrgFollow) TableName() string {
196
+	return "sgj_org_follow"
197
+}

+ 130 - 64
service/admin_service.go 查看文件

@@ -5,6 +5,8 @@ package service
5 5
 import (
6 6
 	"XT_Admin_Api/models"
7 7
 	"XT_Admin_Api/models/admin_models"
8
+	"fmt"
9
+	"strings"
8 10
 	"time"
9 11
 
10 12
 	"github.com/jinzhu/gorm"
@@ -443,8 +445,6 @@ func GetActiveOrgTotalCount() (int64, error) {
443 445
 	return count, nil
444 446
 }
445 447
 
446
-
447
-
448 448
 //获取近七天每天的注册机构总量
449 449
 func GetWeekRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
450 450
 	err = readUserDb.Raw("select count(id) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times  from sgj_user_org  where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_org.ctime)) GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
@@ -475,54 +475,44 @@ func GetWeekNewPatientCount() (weekStatistics []*admin_models.Statistics, err er
475 475
 	return
476 476
 }
477 477
 
478
-
479
-
480
-
481 478
 //获取近七天每天的注册机构总量
482
-func GetWeekRegistedOrgTotalCount() (int64,  error) {
479
+func GetWeekRegistedOrgTotalCount() (int64, error) {
483 480
 	var result admin_models.Count
484 481
 	var err error
485 482
 	err = readUserDb.Raw("select count(id) as count  from sgj_user_org  where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_org.ctime))").Scan(&result).Error
486
-	return result.Count,err
483
+	return result.Count, err
487 484
 }
488 485
 
489 486
 //获取近七天每天的机构活跃账号总量
490
-func GetWeekActiveAdminUserTotalCount() (int64,  error) {
487
+func GetWeekActiveAdminUserTotalCount() (int64, error) {
491 488
 	var result admin_models.Count
492 489
 	var err error
493 490
 	err = readUserDb.Raw("select count(DISTINCT(admin_user_id)) as count  from sgj_user_admin_login_log  where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime))  AND operate_type = 1 ").Scan(&result).Error
494
-	return result.Count,err
491
+	return result.Count, err
495 492
 
496 493
 }
497 494
 
498 495
 //获取近七天新增病人总量
499
-func GetWeekPatientTotalCount() (int64,  error) {
496
+func GetWeekPatientTotalCount() (int64, error) {
500 497
 	var result admin_models.Count
501 498
 	var err error
502 499
 	err = readDb.Raw("select count(DISTINCT(id_card_no)) as count  from xt_patients  where DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(created_time))").Scan(&result).Error
503
-	return result.Count,err
500
+	return result.Count, err
504 501
 
505 502
 }
506 503
 
507
-
508
-
509
-
510
-
511
-
512 504
 //获取近30天每天的注册机构总量
513 505
 func GetMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
514 506
 	err = readUserDb.Raw("select count(id) as count,DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d') as times  from sgj_user_org  where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(sgj_user_org.ctime)) GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
515 507
 	return
516 508
 }
517 509
 
518
-
519 510
 //获取近30天每天的机构活跃总量
520 511
 func GetMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
521 512
 	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times,count(DISTINCT(org_id)) as count From  (select ctime,org_id FROM sgj_user_admin_login_log where app_type = 3 AND org_id > 0 ) T  join sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = T.org_id AND  DATE_FORMAT(date(from_unixtime(T.ctime)) ,'%Y-%m') =DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m') where  DATE_FORMAT(date(from_unixtime(T.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 1 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
522 513
 	return
523 514
 }
524 515
 
525
-
526 516
 //获取近30天每天的机构活跃账号总量
527 517
 func GetMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
528 518
 	err = readUserDb.Raw("select count(DISTINCT(admin_user_id)) as count, DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m-%d')as times  from sgj_user_admin_login_log  where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND sgj_user_admin_login_log.app_type = 3  AND sgj_user_admin_login_log.operate_type = 1 GROUP BY date(from_unixtime(ctime));").Scan(&weekStatistics).Error
@@ -535,45 +525,36 @@ func GetMonthNewPatientCount() (weekStatistics []*admin_models.Statistics, err e
535 525
 	return
536 526
 }
537 527
 
538
-
539
-
540 528
 //获取近30天每天的注册机构总量
541
-func GetMonthRegistedOrgTotalCount() (int64,  error) {
529
+func GetMonthRegistedOrgTotalCount() (int64, error) {
542 530
 	var result admin_models.Count
543 531
 	var err error
544 532
 	err = readUserDb.Raw("select count(id) as count from sgj_user_org  where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(sgj_user_org.ctime))").Scan(&result).Error
545
-	return result.Count,err
533
+	return result.Count, err
546 534
 }
547 535
 
548
-
549 536
 //获取近30天每天的机构活跃账号总量
550
-func GetMonthActiveAdminUserTotalCount() (int64,  error) {
537
+func GetMonthActiveAdminUserTotalCount() (int64, error) {
551 538
 	var result admin_models.Count
552 539
 	var err error
553 540
 	err = readUserDb.Raw("select count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log  where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime))  AND operate_type = 1 ").Scan(&result).Error
554
-	return result.Count,err
541
+	return result.Count, err
555 542
 }
556 543
 
557 544
 //获取近30天每天的机构新增病人总量
558
-func GetMonthNewPatientTotalCount() (int64,  error) {
545
+func GetMonthNewPatientTotalCount() (int64, error) {
559 546
 	var result admin_models.Count
560 547
 	var err error
561 548
 	err = readDb.Raw("select count(DISTINCT(id_card_no)) as count from xt_patients  where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) ").Scan(&result).Error
562
-	return result.Count,err
549
+	return result.Count, err
563 550
 }
564 551
 
565
-
566
-
567
-
568
-
569
-
570 552
 //获取近3个月每个月的注册机构总量
571 553
 func GetThreeMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
572 554
 	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where  DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
573 555
 	return
574 556
 }
575 557
 
576
-
577 558
 //获取近3个月每个月的机构活跃账号总量
578 559
 func GetThreeMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
579 560
 	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m') as times,count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where  DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m')  AND sgj_user_admin_login_log.app_type = 3  AND sgj_user_admin_login_log.operate_type = 1 group by times").Scan(&weekStatistics).Error
@@ -592,77 +573,67 @@ func GetThreeMonthNewPatientCount() (weekStatistics []*admin_models.Statistics,
592 573
 	return
593 574
 }
594 575
 
595
-
596 576
 //获取近3个月每个月的注册机构总量
597
-func GetThreeMonthRegistedOrgTotalCount() (int64,  error) {
577
+func GetThreeMonthRegistedOrgTotalCount() (int64, error) {
598 578
 	var result admin_models.Count
599 579
 	var err error
600 580
 	err = readUserDb.Raw("select count(DISTINCT(id)) as count from sgj_user_org where  DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m')").Scan(&result).Error
601
-	return result.Count,err
581
+	return result.Count, err
602 582
 
603 583
 }
604 584
 
605
-
606 585
 //获取近3个月每个月的机构活跃账号总量
607
-func GetThreeMonthActiveAdminUserTotalCount() (int64,  error) {
586
+func GetThreeMonthActiveAdminUserTotalCount() (int64, error) {
608 587
 	var result admin_models.Count
609 588
 	var err error
610 589
 	err = readUserDb.Raw("select count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where  DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m')  AND operate_type = 1 ").Scan(&result).Error
611
-	return result.Count,err
590
+	return result.Count, err
612 591
 
613 592
 }
614 593
 
615
-
616 594
 //获取近3个月每个月机构新增病人总量
617
-func GetThreeMonthNewPatientTotalCount() (int64,  error) {
595
+func GetThreeMonthNewPatientTotalCount() (int64, error) {
618 596
 	var result admin_models.Count
619 597
 	var err error
620 598
 	err = readDb.Raw("select count(DISTINCT(id_card_no)) as count from xt_patients where  DATE_FORMAT(date(from_unixtime(xt_patients.created_time)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 3 month),'%Y-%m')").Scan(&result).Error
621
-	return result.Count,err
599
+	return result.Count, err
622 600
 
623 601
 }
624 602
 
625
-
626
-
627 603
 //获取近半年每个月的注册机构总量
628 604
 func GetSixMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
629 605
 	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where  DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
630 606
 	return
631 607
 }
632 608
 
633
-
634 609
 //获取近半年每个月的机构活跃账号总量
635 610
 func GetSixMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
636 611
 	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m') as times,count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where  DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m') AND sgj_user_admin_login_log.app_type = 3  AND sgj_user_admin_login_log.operate_type = 1 group by times").Scan(&weekStatistics).Error
637 612
 	return
638 613
 }
639 614
 
640
-
641 615
 //获取近半年每个月的机构活跃总量
642 616
 func GetSixMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
643 617
 	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(ctime)) ,'%Y-%m') as times,count(DISTINCT(org_id)) as count From  (select ctime,org_id FROM sgj_user_admin_login_log where app_type = 3 AND org_id > 0 AND operate_type = 1  ) T  join sgj_xt.xt_dialysis_order ON sgj_xt.xt_dialysis_order.user_org_id = T.org_id AND  DATE_FORMAT(date(from_unixtime(T.ctime)) ,'%Y-%m') =DATE_FORMAT(date(from_unixtime(sgj_xt.xt_dialysis_order.dialysis_date)) ,'%Y-%m') where  DATE_FORMAT(date(from_unixtime(T.ctime)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
644 618
 	return
645 619
 }
646 620
 
647
-
648 621
 //获取近半年每个月机构新增病人总量
649 622
 func GetSixMonthNewPatientCount() (weekStatistics []*admin_models.Statistics, err error) {
650 623
 	err = readDb.Raw("select DATE_FORMAT(date(from_unixtime(xt_patients.created_time)) ,'%Y-%m') as times,count(DISTINCT(id_card_no)) as count from xt_patients where  DATE_FORMAT(date(from_unixtime(xt_patients.created_time)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
651 624
 	return
652 625
 }
653 626
 
654
-
655 627
 //获取近半年每个月的注册机构总量
656
-func GetSixMonthRegistedOrgTotalCount() (int64,  error) {
628
+func GetSixMonthRegistedOrgTotalCount() (int64, error) {
657 629
 	var result admin_models.Count
658 630
 	var err error
659 631
 	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where  DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m')").Scan(&result).Error
660 632
 	return result.Count, err
661 633
 }
662 634
 
663
-
664
-	//获取近半年每个月的机构活跃账号总量
665
-func GetSixMonthActiveAdminUserTotalCount() (int64,  error) {
635
+//获取近半年每个月的机构活跃账号总量
636
+func GetSixMonthActiveAdminUserTotalCount() (int64, error) {
666 637
 	var result admin_models.Count
667 638
 	var err error
668 639
 	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m') as times,count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where  DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m')").Scan(&result).Error
@@ -670,9 +641,8 @@ func GetSixMonthActiveAdminUserTotalCount() (int64,  error) {
670 641
 
671 642
 }
672 643
 
673
-
674 644
 //获取近半年每个月机构新增病人总量
675
-func GetSixMonthNewPatientTotalCount() (int64,  error) {
645
+func GetSixMonthNewPatientTotalCount() (int64, error) {
676 646
 	var result admin_models.Count
677 647
 	var err error
678 648
 	err = readDb.Raw("select DATE_FORMAT(date(from_unixtime(xt_patients.created_time)) ,'%Y-%m') as times,count(DISTINCT(id_card_no)) as count from xt_patients where  DATE_FORMAT(date(from_unixtime(xt_patients.created_time)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 6 month),'%Y-%m')").Scan(&result).Error
@@ -680,16 +650,12 @@ func GetSixMonthNewPatientTotalCount() (int64,  error) {
680 650
 
681 651
 }
682 652
 
683
-
684
-
685
-
686 653
 //获取近1年每个月的注册机构总量
687 654
 func GetYearRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
688 655
 	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where  DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') group by times").Scan(&weekStatistics).Error
689 656
 	return
690 657
 }
691 658
 
692
-
693 659
 //获取近1年每个月的机构活跃账号总量
694 660
 func GetYearActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
695 661
 	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m') as times,count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where  DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>=DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') AND sgj_user_admin_login_log.app_type = 3  AND sgj_user_admin_login_log.operate_type = 1 group by times").Scan(&weekStatistics).Error
@@ -708,9 +674,8 @@ func GetYearNewPatientCount() (weekStatistics []*admin_models.Statistics, err er
708 674
 	return
709 675
 }
710 676
 
711
-
712 677
 //获取近1年每个月的注册机构总量
713
-func GetYearRegistedOrgTotalCount() (int64,  error) {
678
+func GetYearRegistedOrgTotalCount() (int64, error) {
714 679
 	var result admin_models.Count
715 680
 	var err error
716 681
 	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)) ,'%Y-%m') as times,count(DISTINCT(id)) as count from sgj_user_org where  DATE_FORMAT(date(from_unixtime(sgj_user_org.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m')").Scan(&result).Error
@@ -718,18 +683,16 @@ func GetYearRegistedOrgTotalCount() (int64,  error) {
718 683
 
719 684
 }
720 685
 
721
-
722 686
 //获取近1年每个月的机构活跃账号总量
723
-func GetYearActiveAdminUserTotalCount() (int64,  error) {
687
+func GetYearActiveAdminUserTotalCount() (int64, error) {
724 688
 	var result admin_models.Count
725 689
 	var err error
726 690
 	err = readUserDb.Raw("select DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)) ,'%Y-%m') as times,count(DISTINCT(admin_user_id)) as count from sgj_user_admin_login_log where  DATE_FORMAT(date(from_unixtime(sgj_user_admin_login_log.ctime)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m')").Scan(&result).Error
727 691
 	return result.Count, err
728 692
 }
729 693
 
730
-
731 694
 //获取近1年每个月机构新增病人总量
732
-func GetYearNewPatientTotalCount() (int64,  error) {
695
+func GetYearNewPatientTotalCount() (int64, error) {
733 696
 	var result admin_models.Count
734 697
 	var err error
735 698
 	err = readDb.Raw("select count(DISTINCT(id_card_no)) as count from xt_patients where  DATE_FORMAT(date(from_unixtime(xt_patients.created_time)),'%Y-%m')>DATE_FORMAT(date_sub(curdate(), interval 12 month),'%Y-%m') AND status > 0").Scan(&result).Error
@@ -737,5 +700,108 @@ func GetYearNewPatientTotalCount() (int64,  error) {
737 700
 
738 701
 }
739 702
 
703
+func GetAllAdmin() (admin []*admin_models.AdminAccount, err error) {
704
+	err = readUserDb.Model(&admin_models.AdminAccount{}).Where("is_super_admin <> 1 AND (status = 1 OR status = 2)").Find(&admin).Error
705
+	return
706
+}
707
+
708
+func CreateAdmin(admin *admin_models.AdminAccount) (err error) {
709
+	err = readUserDb.Model(&admin_models.AdminAccount{}).Create(&admin).Error
710
+	return
711
+}
712
+
713
+func FindUserInfoByAccount(account string) (admin admin_models.AdminAccount, err error) {
714
+	err = readUserDb.Model(&admin_models.AdminAccount{}).Where("account = ?", account).First(&admin).Error
715
+	return
716
+}
717
+
718
+func FindAdminById(id int64) (admin admin_models.AdminAccount, err error) {
719
+	err = readUserDb.Model(&admin_models.AdminAccount{}).Where("id = ?", id).First(&admin).Error
720
+	return
721
+}
722
+
723
+func UpdateAdmin(admin *admin_models.AdminAccount) (err error) {
724
+	err = readUserDb.Model(&admin_models.AdminAccount{}).Save(&admin).Error
725
+	return
726
+}
727
+
728
+func DeleteAdmin(id int64) (err error) {
729
+	err = readUserDb.Model(&admin_models.AdminAccount{}).Where("id = ?", id).Updates(map[string]interface{}{"status": 0}).Error
730
+	return
731
+}
732
+
733
+func FindAllOrg() (org []*models.Org, err error) {
734
+	err = readUserDb.Select("id, org_name").Where("status = 1").Find(&org).Error
735
+
736
+	return
737
+}
738
+
739
+type FollowViewModel struct {
740
+	models.OrgFollow
741
+	OrgName string `gorm:"column:org_name" json:"org_name"`
742
+}
743
+
744
+func FindFollowOrg(admin_id int64) ([]*FollowViewModel, error) {
745
+	var vms []*FollowViewModel = make([]*FollowViewModel, 0)
746
+	rows, err := readUserDb.Raw("SELECT follow.*, org.org_name as org_name FROM sgj_org_follow as follow join sgj_user_org as org on org.id = follow.org_id  WHERE (follow.admin_user_id = ? AND follow.status = 1)", admin_id).Rows()
747
+	defer rows.Close()
748
+	if err != nil {
749
+		return nil, err
750
+	}
751
+	for rows.Next() {
752
+		var vm FollowViewModel
753
+		readDb.ScanRows(rows, &vm)
754
+		vms = append(vms, &vm)
755
+	}
756
+	fmt.Println(vms)
757
+	return vms, nil
758
+}
759
+
760
+func FindUnFollowOrgByIds(id int64) (org []*models.Org, err error) {
761
+	err = readUserDb.Raw("Select id, org_name From  sgj_user_org  Where NOT EXISTS (Select id, org_name FROM sgj_org_follow Where sgj_org_follow.org_id = sgj_user_org.id AND sgj_org_follow.admin_user_id = ? AND sgj_org_follow.status = 1)", id).Scan(&org).Error
762
+	return
763
+
764
+}
765
+
766
+func CreateFollowInfo(Follows []*models.OrgFollow) (err error) {
767
+	if len(Follows) > 0 {
768
+		utx := writeUserDb.Begin()
769
+		if len(Follows) > 0 {
770
+			thisSQL := "INSERT INTO sgj_org_follow (org_id,admin_user_id,ctime,mtime,status) VALUES "
771
+			insertParams := make([]string, 0)
772
+			insertData := make([]interface{}, 0)
773
+			for _, info := range Follows {
774
+				insertParams = append(insertParams, "(?,?,?,?,?)")
775
+				insertData = append(insertData, info.OrgId)
776
+				insertData = append(insertData, info.AdminUserId)
777
+				insertData = append(insertData, info.Ctime)
778
+				insertData = append(insertData, info.Mtime)
779
+				insertData = append(insertData, info.Status)
780
+			}
781
+			thisSQL += strings.Join(insertParams, ", ")
782
+			err = utx.Exec(thisSQL, insertData...).Error
783
+			if err != nil {
784
+				utx.Rollback()
785
+				return
786
+			}
787
+		}
788
+		utx.Commit()
789
+	}
790
+	return
791
+
792
+}
793
+
794
+func UpdateFollow(follow *models.OrgFollow) {
795
+	readUserDb.Model(&models.OrgFollow{}).Save(follow)
796
+	return
797
+}
740 798
 
799
+func FindFollowRecordByID(follow *models.OrgFollow) (info models.OrgFollow, err error) {
800
+	err = readUserDb.Model(&models.OrgFollow{}).Where("org_id = ? AND admin_user_id = ?", follow.OrgId, follow.AdminUserId).First(&info).Error
801
+	return
802
+}
741 803
 
804
+func FindFollowInfoById(org_id int64, admin_user_id int64) (info models.OrgFollow, err error) {
805
+	err = readUserDb.Model(&models.OrgFollow{}).Where("org_id = ? AND status = 1 AND admin_user_id = ?", org_id, admin_user_id).First(&info).Error
806
+	return
807
+}

+ 279 - 106
service/org_service.go 查看文件

@@ -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
+//}