Browse Source

机构功能相关接口

csx 5 years ago
parent
commit
7dde6eb9c4

+ 1 - 1
conf/app.conf View File

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

+ 22 - 0
controllers/admin_api_controllers/admin_api_router_register.go View File

20
 	beego.Router("/admin/api/orginfo", &OrgAPIController{}, "get:GetOrgInfo")
20
 	beego.Router("/admin/api/orginfo", &OrgAPIController{}, "get:GetOrgInfo")
21
 	beego.Router("/admin/api/org/statistics", &OrgAPIController{}, "get:GetOrgDialysisOrderStatistics")
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 View File

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

+ 131 - 28
controllers/admin_api_controllers/org_api_controller.go View File

14
 }
14
 }
15
 
15
 
16
 func (this *OrgAPIController) GetOrgList() {
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
 	start_time := this.GetString("start_time")
19
 	start_time := this.GetString("start_time")
20
 	end_time := this.GetString("end_time")
20
 	end_time := this.GetString("end_time")
21
-	province,_ := this.GetInt64("province")
22
-	city,_ := this.GetInt64("city")
23
-	district,_ := this.GetInt64("district")
24
-	follow,_ := this.GetInt64("follow")
21
+	province, _ := this.GetInt64("province")
22
+	city, _ := this.GetInt64("city")
23
+	district, _ := this.GetInt64("district")
24
+	follow, _ := this.GetInt64("follow")
25
 	keyword := this.GetString("keyword")
25
 	keyword := this.GetString("keyword")
26
 	page, _ := this.GetInt64("page", 0)
26
 	page, _ := this.GetInt64("page", 0)
27
 	limit, _ := this.GetInt64("limit", 0)
27
 	limit, _ := this.GetInt64("limit", 0)
57
 
57
 
58
 	adminInfo := this.GetAdminInfo()
58
 	adminInfo := this.GetAdminInfo()
59
 	if adminInfo.Admin.IsSuperAdmin == 1 {
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
 		if err != nil {
61
 		if err != nil {
62
 
62
 
63
 		} else {
63
 		} else {
64
 			this.ServeSuccessJSON(map[string]interface{}{
64
 			this.ServeSuccessJSON(map[string]interface{}{
65
-				"list": list,
66
-				"total":total,
65
+				"list":  list,
66
+				"total": total,
67
 			})
67
 			})
68
 		}
68
 		}
69
 	} else {
69
 	} else {
72
 }
72
 }
73
 
73
 
74
 func (this *OrgAPIController) GetOrgInfo() {
74
 func (this *OrgAPIController) GetOrgInfo() {
75
-	org_id, _:=this.GetInt64("org_id",0)
75
+	org_id, _ := this.GetInt64("org_id", 0)
76
 	info, err := service.GetOrgDetailInfo(org_id)
76
 	info, err := service.GetOrgDetailInfo(org_id)
77
 	province, _ := service.GetDistrictsById(info.Province)
77
 	province, _ := service.GetDistrictsById(info.Province)
78
 	city, _ := service.GetDistrictsById(info.City)
78
 	city, _ := service.GetDistrictsById(info.City)
85
 		return
85
 		return
86
 	} else {
86
 	} else {
87
 		this.ServeSuccessJSON(map[string]interface{}{
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
 func (this *OrgAPIController) GetOrgDialysisOrderStatistics() {
95
 func (this *OrgAPIController) GetOrgDialysisOrderStatistics() {
96
-	org_id, _:=this.GetInt64("org_id",0)
96
+	org_id, _ := this.GetInt64("org_id", 0)
97
 	range_data := this.GetString("range_data")
97
 	range_data := this.GetString("range_data")
98
 	range_type, _ := this.GetInt64("range_type")
98
 	range_type, _ := this.GetInt64("range_type")
99
 	statistics_type, _ := this.GetInt64("type")
99
 	statistics_type, _ := this.GetInt64("type")
101
 	var parseDateErr error
101
 	var parseDateErr error
102
 	var rangeTimeStamp int64
102
 	var rangeTimeStamp int64
103
 
103
 
104
-
105
-
106
-
107
 	var orgDialysisOrderStatistics []*admin_models.Statistics
104
 	var orgDialysisOrderStatistics []*admin_models.Statistics
108
 
105
 
109
-	switch range_type{
106
+	switch range_type {
110
 	case 1: //今天
107
 	case 1: //今天
111
 		if len(range_data) > 0 {
108
 		if len(range_data) > 0 {
112
 			rangeDate, parseDateErr = utils.ParseTimeStringToTime("2006-01-02", range_data)
109
 			rangeDate, parseDateErr = utils.ParseTimeStringToTime("2006-01-02", range_data)
119
 			rangeTimeStamp = 0
116
 			rangeTimeStamp = 0
120
 		}
117
 		}
121
 		now := time.Now().Unix()
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
 		if err != nil {
120
 		if err != nil {
124
 			this.ErrorLog("错误:%v", err)
121
 			this.ErrorLog("错误:%v", err)
125
 			return
122
 			return
130
 			})
127
 			})
131
 		}
128
 		}
132
 		break
129
 		break
133
-	case 2:  //昨天
130
+	case 2: //昨天
134
 		if len(range_data) > 0 {
131
 		if len(range_data) > 0 {
135
 			rangeDate, parseDateErr = utils.ParseTimeStringToTime("2006-01-02", range_data)
132
 			rangeDate, parseDateErr = utils.ParseTimeStringToTime("2006-01-02", range_data)
136
 			if parseDateErr != nil {
133
 			if parseDateErr != nil {
142
 			rangeTimeStamp = 0
139
 			rangeTimeStamp = 0
143
 		}
140
 		}
144
 		now := time.Now().Unix()
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
 		if err != nil {
143
 		if err != nil {
147
 			this.ErrorLog("错误:%v", err)
144
 			this.ErrorLog("错误:%v", err)
148
 			return
145
 			return
153
 			})
150
 			})
154
 		}
151
 		}
155
 		break
152
 		break
156
-	case 3://一周
153
+	case 3: //一周
157
 		var err error
154
 		var err error
158
 		orgDialysisOrderStatistics, err = service.GetWeekOrgDialysisCount(statistics_type, org_id)
155
 		orgDialysisOrderStatistics, err = service.GetWeekOrgDialysisCount(statistics_type, org_id)
159
 		if err != nil {
156
 		if err != nil {
165
 			})
162
 			})
166
 		}
163
 		}
167
 		break
164
 		break
168
-	case 4://一个月
165
+	case 4: //一个月
169
 		var err error
166
 		var err error
170
 		orgDialysisOrderStatistics, err = service.GetMonthOrgDialysisCount(statistics_type, org_id)
167
 		orgDialysisOrderStatistics, err = service.GetMonthOrgDialysisCount(statistics_type, org_id)
171
 		if err != nil {
168
 		if err != nil {
177
 			})
174
 			})
178
 		}
175
 		}
179
 		break
176
 		break
180
-	case 5://三个月
177
+	case 5: //三个月
181
 		var err error
178
 		var err error
182
 		orgDialysisOrderStatistics, err = service.GetThreeMonthOrgDialysisCount(statistics_type, org_id)
179
 		orgDialysisOrderStatistics, err = service.GetThreeMonthOrgDialysisCount(statistics_type, org_id)
183
 		if err != nil {
180
 		if err != nil {
189
 			})
186
 			})
190
 		}
187
 		}
191
 		break
188
 		break
192
-	case 6://半年
189
+	case 6: //半年
193
 		var err error
190
 		var err error
194
 		orgDialysisOrderStatistics, err = service.GetSixMonthOrgDialysisCount(statistics_type, org_id)
191
 		orgDialysisOrderStatistics, err = service.GetSixMonthOrgDialysisCount(statistics_type, org_id)
195
 		if err != nil {
192
 		if err != nil {
201
 			})
198
 			})
202
 		}
199
 		}
203
 		break
200
 		break
204
-	case 7://一年
201
+	case 7: //一年
205
 		var err error
202
 		var err error
206
 		orgDialysisOrderStatistics, err = service.GetYearOrgDialysisCount(statistics_type, org_id)
203
 		orgDialysisOrderStatistics, err = service.GetYearOrgDialysisCount(statistics_type, org_id)
207
 		if err != nil {
204
 		if err != nil {
225
 	return
222
 	return
226
 }
223
 }
227
 
224
 
228
-
229
-func (this *OrgAPIController)GetInitData(){
225
+func (this *OrgAPIController) GetInitData() {
230
 	provinces, _ := service.GetDistrictsByUpid(0)
226
 	provinces, _ := service.GetDistrictsByUpid(0)
227
+	follower, _ := service.FindAllFollower()
228
+
231
 	this.ServeSuccessJSON(map[string]interface{}{
229
 	this.ServeSuccessJSON(map[string]interface{}{
232
 		"provinces": provinces,
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 View File

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 View File

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

+ 7 - 6
models/admin_models/admin_models.go View File

3
 package admin_models
3
 package admin_models
4
 
4
 
5
 type AdminAccount struct {
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
 	IsSuperAdmin int64  `gorm:"column:is_super_admin" json:"is_super_admin"`
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
 func (AdminAccount) TableName() string {
16
 func (AdminAccount) TableName() string {

+ 1 - 0
models/admin_user_models.go View File

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

+ 59 - 0
models/org_models.go View File

1
 package models
1
 package models
2
 
2
 
3
+import "XT_Admin_Api/models/admin_models"
4
+
3
 type Org struct {
5
 type Org struct {
4
 	Id                int64             `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"` // 机构 ID
6
 	Id                int64             `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"` // 机构 ID
5
 	Creator           int64             `json:"creator"`                              // 创建者,即管理员用户的 id
7
 	Creator           int64             `json:"creator"`                              // 创建者,即管理员用户的 id
28
 	OrgGallery        []*OrgGallery     `gorm:"ForeignKey:OrgId" json:"org_gallery"`
30
 	OrgGallery        []*OrgGallery     `gorm:"ForeignKey:OrgId" json:"org_gallery"`
29
 	AdminUserLoginLog AdminUserLoginLog `gorm:"ForeignKey:OrgId" json:"log"`
31
 	AdminUserLoginLog AdminUserLoginLog `gorm:"ForeignKey:OrgId" json:"log"`
30
 	AdminUser         AdminUser         `gorm:"ForeignKey:Id" json:"admin"`
32
 	AdminUser         AdminUser         `gorm:"ForeignKey:Id" json:"admin"`
33
+	OrgFollow         []*OrgFollow      `gorm:"ForeignKey:OrgId" json:"follow"`
31
 }
34
 }
32
 
35
 
33
 func (Org) TableName() string {
36
 func (Org) TableName() string {
136
 func (UserOrgType) TableName() string {
139
 func (UserOrgType) TableName() string {
137
 	return "sgj_user_org_type"
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 View File

5
 import (
5
 import (
6
 	"XT_Admin_Api/models"
6
 	"XT_Admin_Api/models"
7
 	"XT_Admin_Api/models/admin_models"
7
 	"XT_Admin_Api/models/admin_models"
8
+	"fmt"
9
+	"strings"
8
 	"time"
10
 	"time"
9
 
11
 
10
 	"github.com/jinzhu/gorm"
12
 	"github.com/jinzhu/gorm"
443
 	return count, nil
445
 	return count, nil
444
 }
446
 }
445
 
447
 
446
-
447
-
448
 //获取近七天每天的注册机构总量
448
 //获取近七天每天的注册机构总量
449
 func GetWeekRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
449
 func GetWeekRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
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
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
 	return
475
 	return
476
 }
476
 }
477
 
477
 
478
-
479
-
480
-
481
 //获取近七天每天的注册机构总量
478
 //获取近七天每天的注册机构总量
482
-func GetWeekRegistedOrgTotalCount() (int64,  error) {
479
+func GetWeekRegistedOrgTotalCount() (int64, error) {
483
 	var result admin_models.Count
480
 	var result admin_models.Count
484
 	var err error
481
 	var err error
485
 	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
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
 	var result admin_models.Count
488
 	var result admin_models.Count
492
 	var err error
489
 	var err error
493
 	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
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
 	var result admin_models.Count
497
 	var result admin_models.Count
501
 	var err error
498
 	var err error
502
 	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
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
 //获取近30天每天的注册机构总量
504
 //获取近30天每天的注册机构总量
513
 func GetMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
505
 func GetMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
514
 	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
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
 	return
507
 	return
516
 }
508
 }
517
 
509
 
518
-
519
 //获取近30天每天的机构活跃总量
510
 //获取近30天每天的机构活跃总量
520
 func GetMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
511
 func GetMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
521
 	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
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
 	return
513
 	return
523
 }
514
 }
524
 
515
 
525
-
526
 //获取近30天每天的机构活跃账号总量
516
 //获取近30天每天的机构活跃账号总量
527
 func GetMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
517
 func GetMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
528
 	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
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
 	return
525
 	return
536
 }
526
 }
537
 
527
 
538
-
539
-
540
 //获取近30天每天的注册机构总量
528
 //获取近30天每天的注册机构总量
541
-func GetMonthRegistedOrgTotalCount() (int64,  error) {
529
+func GetMonthRegistedOrgTotalCount() (int64, error) {
542
 	var result admin_models.Count
530
 	var result admin_models.Count
543
 	var err error
531
 	var err error
544
 	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
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
 //获取近30天每天的机构活跃账号总量
536
 //获取近30天每天的机构活跃账号总量
550
-func GetMonthActiveAdminUserTotalCount() (int64,  error) {
537
+func GetMonthActiveAdminUserTotalCount() (int64, error) {
551
 	var result admin_models.Count
538
 	var result admin_models.Count
552
 	var err error
539
 	var err error
553
 	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
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
 //获取近30天每天的机构新增病人总量
544
 //获取近30天每天的机构新增病人总量
558
-func GetMonthNewPatientTotalCount() (int64,  error) {
545
+func GetMonthNewPatientTotalCount() (int64, error) {
559
 	var result admin_models.Count
546
 	var result admin_models.Count
560
 	var err error
547
 	var err error
561
 	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
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
 //获取近3个月每个月的注册机构总量
552
 //获取近3个月每个月的注册机构总量
571
 func GetThreeMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
553
 func GetThreeMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
572
 	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
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
 	return
555
 	return
574
 }
556
 }
575
 
557
 
576
-
577
 //获取近3个月每个月的机构活跃账号总量
558
 //获取近3个月每个月的机构活跃账号总量
578
 func GetThreeMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
559
 func GetThreeMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
579
 	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
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
 	return
573
 	return
593
 }
574
 }
594
 
575
 
595
-
596
 //获取近3个月每个月的注册机构总量
576
 //获取近3个月每个月的注册机构总量
597
-func GetThreeMonthRegistedOrgTotalCount() (int64,  error) {
577
+func GetThreeMonthRegistedOrgTotalCount() (int64, error) {
598
 	var result admin_models.Count
578
 	var result admin_models.Count
599
 	var err error
579
 	var err error
600
 	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
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
 //获取近3个月每个月的机构活跃账号总量
585
 //获取近3个月每个月的机构活跃账号总量
607
-func GetThreeMonthActiveAdminUserTotalCount() (int64,  error) {
586
+func GetThreeMonthActiveAdminUserTotalCount() (int64, error) {
608
 	var result admin_models.Count
587
 	var result admin_models.Count
609
 	var err error
588
 	var err error
610
 	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
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
 //获取近3个月每个月机构新增病人总量
594
 //获取近3个月每个月机构新增病人总量
617
-func GetThreeMonthNewPatientTotalCount() (int64,  error) {
595
+func GetThreeMonthNewPatientTotalCount() (int64, error) {
618
 	var result admin_models.Count
596
 	var result admin_models.Count
619
 	var err error
597
 	var err error
620
 	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
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
 func GetSixMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
604
 func GetSixMonthRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
629
 	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
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
 	return
606
 	return
631
 }
607
 }
632
 
608
 
633
-
634
 //获取近半年每个月的机构活跃账号总量
609
 //获取近半年每个月的机构活跃账号总量
635
 func GetSixMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
610
 func GetSixMonthActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
636
 	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
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
 	return
612
 	return
638
 }
613
 }
639
 
614
 
640
-
641
 //获取近半年每个月的机构活跃总量
615
 //获取近半年每个月的机构活跃总量
642
 func GetSixMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
616
 func GetSixMonthActiveOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
643
 	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
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
 	return
618
 	return
645
 }
619
 }
646
 
620
 
647
-
648
 //获取近半年每个月机构新增病人总量
621
 //获取近半年每个月机构新增病人总量
649
 func GetSixMonthNewPatientCount() (weekStatistics []*admin_models.Statistics, err error) {
622
 func GetSixMonthNewPatientCount() (weekStatistics []*admin_models.Statistics, err error) {
650
 	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
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
 	return
624
 	return
652
 }
625
 }
653
 
626
 
654
-
655
 //获取近半年每个月的注册机构总量
627
 //获取近半年每个月的注册机构总量
656
-func GetSixMonthRegistedOrgTotalCount() (int64,  error) {
628
+func GetSixMonthRegistedOrgTotalCount() (int64, error) {
657
 	var result admin_models.Count
629
 	var result admin_models.Count
658
 	var err error
630
 	var err error
659
 	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
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
 	return result.Count, err
632
 	return result.Count, err
661
 }
633
 }
662
 
634
 
663
-
664
-	//获取近半年每个月的机构活跃账号总量
665
-func GetSixMonthActiveAdminUserTotalCount() (int64,  error) {
635
+//获取近半年每个月的机构活跃账号总量
636
+func GetSixMonthActiveAdminUserTotalCount() (int64, error) {
666
 	var result admin_models.Count
637
 	var result admin_models.Count
667
 	var err error
638
 	var err error
668
 	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
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
 
641
 
671
 }
642
 }
672
 
643
 
673
-
674
 //获取近半年每个月机构新增病人总量
644
 //获取近半年每个月机构新增病人总量
675
-func GetSixMonthNewPatientTotalCount() (int64,  error) {
645
+func GetSixMonthNewPatientTotalCount() (int64, error) {
676
 	var result admin_models.Count
646
 	var result admin_models.Count
677
 	var err error
647
 	var err error
678
 	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
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
 
650
 
681
 }
651
 }
682
 
652
 
683
-
684
-
685
-
686
 //获取近1年每个月的注册机构总量
653
 //获取近1年每个月的注册机构总量
687
 func GetYearRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
654
 func GetYearRegistedOrgCount() (weekStatistics []*admin_models.Statistics, err error) {
688
 	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
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
 	return
656
 	return
690
 }
657
 }
691
 
658
 
692
-
693
 //获取近1年每个月的机构活跃账号总量
659
 //获取近1年每个月的机构活跃账号总量
694
 func GetYearActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
660
 func GetYearActiveAdminUserCount() (weekStatistics []*admin_models.Statistics, err error) {
695
 	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
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
 	return
674
 	return
709
 }
675
 }
710
 
676
 
711
-
712
 //获取近1年每个月的注册机构总量
677
 //获取近1年每个月的注册机构总量
713
-func GetYearRegistedOrgTotalCount() (int64,  error) {
678
+func GetYearRegistedOrgTotalCount() (int64, error) {
714
 	var result admin_models.Count
679
 	var result admin_models.Count
715
 	var err error
680
 	var err error
716
 	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
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
 
683
 
719
 }
684
 }
720
 
685
 
721
-
722
 //获取近1年每个月的机构活跃账号总量
686
 //获取近1年每个月的机构活跃账号总量
723
-func GetYearActiveAdminUserTotalCount() (int64,  error) {
687
+func GetYearActiveAdminUserTotalCount() (int64, error) {
724
 	var result admin_models.Count
688
 	var result admin_models.Count
725
 	var err error
689
 	var err error
726
 	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
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
 	return result.Count, err
691
 	return result.Count, err
728
 }
692
 }
729
 
693
 
730
-
731
 //获取近1年每个月机构新增病人总量
694
 //获取近1年每个月机构新增病人总量
732
-func GetYearNewPatientTotalCount() (int64,  error) {
695
+func GetYearNewPatientTotalCount() (int64, error) {
733
 	var result admin_models.Count
696
 	var result admin_models.Count
734
 	var err error
697
 	var err error
735
 	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
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
 
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 View File

9
 	"time"
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
 	offset := (page - 1) * limit
13
 	offset := (page - 1) * limit
14
 	fmt.Println(offset)
14
 	fmt.Println(offset)
15
 	db := readUserDb.Model(&models.Org{})
15
 	db := readUserDb.Model(&models.Org{})
16
-	if len(keyword) > 0{
16
+
17
+	if len(keyword) > 0 {
17
 		likeKey := "%" + keyword + "%"
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
 		switch active_status {
22
 		switch active_status {
22
 		case 1:
23
 		case 1:
23
 			now := time.Now()
24
 			now := time.Now()
24
 			zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
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
 			break
27
 			break
27
 		case 2:
28
 		case 2:
28
 			db = db.Joins("JOIN sgj_user_admin_login_log on sgj_user_admin_login_log.org_id = sgj_user_org.id AND DATE_SUB(CURDATE(), INTERVAL 7 DAY) <= date(from_unixtime(sgj_user_admin_login_log.ctime)) AND sgj_user_admin_login_log.app_type = 3 AND sgj_user_admin_login_log.operate_type = 1 ")
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
 		case 1:
40
 		case 1:
40
 			now := time.Now()
41
 			now := time.Now()
41
 			zeroHourTimeOfToday := utils.ZeroHourTimeOfDay(now)
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
 			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
 			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
 			break
46
 			break
59
 
60
 
60
 			break
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
 		if start_time != 0 {
75
 		if start_time != 0 {
78
 			db = db.Where("sgj_user_org.ctime<=?", end_time)
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
 		return db.Model(&models.AdminUserLoginLog{}).Where("id = (SELECT max(id))")
90
 		return db.Model(&models.AdminUserLoginLog{}).Where("id = (SELECT max(id))")
84
 	}).Count(&total).Offset(offset).Limit(limit).Group("id").Find(&list).Error
91
 	}).Count(&total).Offset(offset).Limit(limit).Group("id").Find(&list).Error
85
 	return
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
 		return db.Model(&models.AdminUserLoginLog{}).Where("id = (SELECT max(id))")
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
 	return
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
 	err = readUserDb.Model(&models.District{}).Where("id = ? ", id).First(&district).Error
103
 	err = readUserDb.Model(&models.District{}).Where("id = ? ", id).First(&district).Error
98
 	return
104
 	return
99
 }
105
 }
100
 
106
 
101
-func GetAllOrgType()(types []*models.OrgType, err error){
107
+func GetAllOrgType() (types []*models.OrgType, err error) {
102
 	err = readUserDb.Model(&models.OrgType{}).Find(&types).Error
108
 	err = readUserDb.Model(&models.OrgType{}).Find(&types).Error
103
 	return
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
 	var counts int64
114
 	var counts int64
108
 
115
 
109
 	switch statices_type {
116
 	switch statices_type {
110
 	case 1: //病人管理
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
 		if err != nil {
119
 		if err != nil {
113
 			return 0, err
120
 			return 0, err
114
 		}
121
 		}
117
 		}
124
 		}
118
 		break
125
 		break
119
 	case 2: //透析处方
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
 		if err != nil {
128
 		if err != nil {
122
 			return 0, err
129
 			return 0, err
123
 		}
130
 		}
126
 		}
133
 		}
127
 		break
134
 		break
128
 	case 3: //接诊评估
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
 		if err != nil {
137
 		if err != nil {
131
 			return 0, err
138
 			return 0, err
132
 		}
139
 		}
135
 		}
142
 		}
136
 		break
143
 		break
137
 	case 4: //透前评估
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
 		if err != nil {
146
 		if err != nil {
140
 			return 0, err
147
 			return 0, err
141
 		}
148
 		}
143
 			rows.Scan(&counts)
150
 			rows.Scan(&counts)
144
 		}
151
 		}
145
 		break
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
 		if err != nil {
155
 		if err != nil {
149
 			return 0, err
156
 			return 0, err
150
 		}
157
 		}
153
 		}
160
 		}
154
 		break
161
 		break
155
 	case 6: //双人核对
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
 		if err != nil {
164
 		if err != nil {
158
 			return 0, err
165
 			return 0, err
159
 		}
166
 		}
162
 		}
169
 		}
163
 		break
170
 		break
164
 	case 7: //透析上机
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
 		if err != nil {
173
 		if err != nil {
167
 			return 0, err
174
 			return 0, err
168
 		}
175
 		}
172
 		break
179
 		break
173
 
180
 
174
 	case 8: //透析监测
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
 		if err != nil {
183
 		if err != nil {
177
 			return 0, err
184
 			return 0, err
178
 		}
185
 		}
181
 		}
188
 		}
182
 		break
189
 		break
183
 	case 9: //透析下机
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
 		if err != nil {
192
 		if err != nil {
186
 			return 0, err
193
 			return 0, err
187
 		}
194
 		}
190
 		}
197
 		}
191
 		break
198
 		break
192
 	case 10: //透后评估
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
 		if err != nil {
201
 		if err != nil {
195
 			return 0, err
202
 			return 0, err
196
 		}
203
 		}
199
 		}
206
 		}
200
 		break
207
 		break
201
 	case 11: //入库单
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
 		if err != nil {
210
 		if err != nil {
204
 			return 0, err
211
 			return 0, err
205
 		}
212
 		}
208
 		}
215
 		}
209
 		break
216
 		break
210
 	case 12: //出库单
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
 		if err != nil {
219
 		if err != nil {
213
 			return 0, err
220
 			return 0, err
214
 		}
221
 		}
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
 	fmt.Println(statices_type)
232
 	fmt.Println(statices_type)
226
 
233
 
227
 	switch statices_type {
234
 	switch statices_type {
230
 
237
 
231
 		break
238
 		break
232
 	case 2: //透析处方
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
 		break
242
 		break
236
 	case 3: //接诊评估
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
 		break
246
 		break
240
 	case 4: //透前评估
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
 		break
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
 		break
254
 		break
248
 	case 6: //双人核对
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
 		break
258
 		break
252
 	case 7: //透析上机
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
 		break
261
 		break
255
 
262
 
256
 	case 8: //透析监测
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
 		break
265
 		break
259
 	case 9: //透析下机
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
 		break
269
 		break
263
 	case 10: //透后评估
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
 		break
272
 		break
266
 	case 11: //入库单
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
 		break
275
 		break
269
 	case 12: //出库单
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
 		break
278
 		break
272
 	}
279
 	}
273
 
280
 
274
 	return
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
 	switch statices_type {
285
 	switch statices_type {
281
 	case 1: //病人管理
286
 	case 1: //病人管理
282
 		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m-%d') as times  from xt_patients  where DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= date(from_unixtime(created_time)) AND status = 1  AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
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
 		break
289
 		break
285
 	case 2: //透析处方
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
 		break
293
 		break
289
 	case 3: //接诊评估
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
 		break
297
 		break
293
 	case 4: //透前评估
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
 		break
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
 		break
305
 		break
301
 	case 6: //双人核对
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
 		break
309
 		break
305
 	case 7: //透析下机
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
 		break
312
 		break
308
 
313
 
309
 	case 8: //透析监测
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
 		break
316
 		break
312
 	case 9: //透析下机
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
 		break
320
 		break
316
 	case 10: //透后评估
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
 		break
323
 		break
319
 	case 11: //入库单
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
 		break
326
 		break
322
 	case 12: //出库单
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
 		break
329
 		break
325
 	}
330
 	}
326
 	return
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
 	switch statices_type {
335
 	switch statices_type {
332
 	case 1: //病人管理
336
 	case 1: //病人管理
333
 		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_patients  where DATE_SUB(CURDATE(), INTERVAL 3 MONTH) <= date(from_unixtime(created_time)) AND status = 1  AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
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
 		break
339
 		break
336
 	case 2: //透析处方
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
 		break
343
 		break
340
 	case 3: //接诊评估
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
 		break
347
 		break
344
 	case 4: //透前评估
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
 		break
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
 		break
355
 		break
352
 	case 6: //双人核对
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
 		break
359
 		break
356
 	case 7: //透析上机
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
 		break
362
 		break
359
 
363
 
360
 	case 8: //透析监测
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
 		break
366
 		break
363
 	case 9: //透析下机
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
 		break
370
 		break
367
 	case 10: //透后评估
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
 		break
373
 		break
370
 	case 11: //入库单
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
 		break
376
 		break
373
 	case 12: //出库单
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
 		break
379
 		break
376
 	}
380
 	}
377
 	return
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
 	switch statices_type {
385
 	switch statices_type {
384
 	case 1: //病人管理
386
 	case 1: //病人管理
385
 		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_patients  where DATE_SUB(CURDATE(), INTERVAL 6 MONTH) <= date(from_unixtime(created_time)) AND status = 1  AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
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
 		break
389
 		break
388
 	case 2: //透析处方
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
 		break
393
 		break
392
 	case 3: //接诊评估
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
 		break
397
 		break
396
 	case 4: //透前评估
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
 		break
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
 		break
405
 		break
404
 	case 6: //双人核对
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
 		break
409
 		break
408
 	case 7: //透析上机
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
 		break
412
 		break
411
 
413
 
412
 	case 8: //透析监测
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
 		break
416
 		break
415
 	case 9: //透析下机
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
 		break
420
 		break
419
 	case 10: //透后评估
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
 		break
423
 		break
422
 	case 11: //入库单
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
 		break
426
 		break
425
 	case 12: //出库单
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
 		break
429
 		break
428
 	}
430
 	}
429
 	return
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
 	switch statices_type {
435
 	switch statices_type {
437
 	case 1: //病人管理
436
 	case 1: //病人管理
438
 		err = readDb.Raw("select count(distinct id) as count, DATE_FORMAT(date(from_unixtime(created_time)) ,'%Y-%m') as times  from xt_patients  where DATE_SUB(CURDATE(), INTERVAL 12 MONTH) <= date(from_unixtime(created_time)) AND status = 1  AND user_org_id = ? GROUP BY times", org_id).Scan(&weekStatistics).Error
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
 		break
439
 		break
441
 	case 2: //透析处方
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
 		break
443
 		break
445
 	case 3: //接诊评估
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
 		break
447
 		break
449
 	case 4: //透前评估
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
 		break
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
 		break
455
 		break
457
 	case 6: //双人核对
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
 		break
459
 		break
461
 	case 7: //透析上机
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
 		break
462
 		break
464
 
463
 
465
 	case 8: //透析监测
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
 		break
466
 		break
468
 	case 9: //透析下机
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
 		break
470
 		break
472
 	case 10: //透后评估
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
 		break
473
 		break
475
 	case 11: //入库单
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
 		break
476
 		break
478
 	case 12: //出库单
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
 		break
479
 		break
481
 	}
480
 	}
482
 	return
481
 	return
486
 	err = readUserDb.Model(&models.District{}).Where("upid=?", id).Find(&dis).Error
485
 	err = readUserDb.Model(&models.District{}).Where("upid=?", id).Find(&dis).Error
487
 	return
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
+//}