Bladeren bron

Merge branch 'master' of http://git.shengws.com/csx/XT_Admin_Api

xiaoming_global 5 jaren geleden
bovenliggende
commit
c1c9c118b3

+ 4 - 0
.idea/encodings.xml Bestand weergeven

@@ -0,0 +1,4 @@
1
+<?xml version="1.0" encoding="UTF-8"?>
2
+<project version="4">
3
+  <component name="Encoding" addBOMForNewFiles="with NO BOM" />
4
+</project>

+ 5 - 7
conf/app.conf Bestand weergeven

@@ -1,5 +1,5 @@
1 1
 appname = 血透
2
-httpport = 9529
2
+httpport = 9550
3 3
 runmode = dev
4 4
 
5 5
 copyrequestbody = true
@@ -42,9 +42,8 @@ appsecret="61ee2e6268497d5aa9de0b0187c39aea"
42 42
 
43 43
 
44 44
 [prod]
45
-httpdomain = https://api.xt.kuyicloud.com
46
-sso_domain = https://sso.kuyicloud.com
47
-front_end_domain = "https://xt.kuyicloud.com/#"
45
+httpdomain = http://api.szjkhd.com
46
+
48 47
 
49 48
 readmysqlhost = shengws1.mysql.rds.aliyuncs.com
50 49
 readmysqlport = 3306
@@ -81,9 +80,8 @@ redisdb = 0
81 80
 
82 81
 
83 82
 [dev]
84
-httpdomain = http://api.xt.test.sgjyun.com
85
-sso_domain = https://testsso.sgjyun.com
86
-front_end_domain = "http://xt.test.sgjyun.com/#"
83
+httpdomain = http://api.szjkhd.com
84
+
87 85
 
88 86
 readmysqlhost = rm-wz9rg531npf61q03tro.mysql.rds.aliyuncs.com
89 87
 readmysqlport = 3306

+ 29 - 7
controllers/admin_api_controllers/admin_api_router_register.go Bestand weergeven

@@ -6,13 +6,13 @@ import "github.com/astaxie/beego"
6 6
 func AdminAPIControllersRegisterRouters() {
7 7
 	beego.Router("/admin/api/login/pwd", &LoginAPIController{}, "post:LoginByPwd")
8 8
 
9
-	beego.Router("/admin/api/org/regist", &AnalysisAPIController{}, "get:RegistOrg")
10
-	beego.Router("/admin/api/org/active", &AnalysisAPIController{}, "get:ActiveOrg")
11
-	beego.Router("/admin/api/user/active", &AnalysisAPIController{}, "get:ActiveUser")
12
-	beego.Router("/admin/api/org/expiring", &AnalysisAPIController{}, "get:ExpiringOrg")
13
-	beego.Router("/admin/api/dialysis/analysis", &AnalysisAPIController{}, "get:DialysisAnalysis")
14
-	beego.Router("/admin/api/monitor/analysis", &AnalysisAPIController{}, "get:MonitorAnalysis")
15
-	beego.Router("/admin/api/patient/analysis", &AnalysisAPIController{}, "get:PatientAnalysis")
9
+	//beego.Router("/admin/api/org/regist", &AnalysisAPIController{}, "get:RegistOrg")
10
+	//beego.Router("/admin/api/org/active", &AnalysisAPIController{}, "get:ActiveOrg")
11
+	//beego.Router("/admin/api/user/active", &AnalysisAPIController{}, "get:ActiveUser")
12
+	//beego.Router("/admin/api/org/expiring", &AnalysisAPIController{}, "get:ExpiringOrg")
13
+	//beego.Router("/admin/api/dialysis/analysis", &AnalysisAPIController{}, "get:DialysisAnalysis")
14
+	//beego.Router("/admin/api/monitor/analysis", &AnalysisAPIController{}, "get:MonitorAnalysis")
15
+	//beego.Router("/admin/api/patient/analysis", &AnalysisAPIController{}, "get:PatientAnalysis")
16 16
 	beego.Router("/admin/api/home/statistics", &AnalysisAPIController{}, "get:HomeStatistics")
17 17
 	beego.Router("/admin/api/getdistrictsbyupid", &OrgAPIController{}, "get:GetDistrictsByUpid")
18 18
 	beego.Router("/admin/api/org", &OrgAPIController{}, "get:GetOrgList")
@@ -20,4 +20,26 @@ func AdminAPIControllersRegisterRouters() {
20 20
 	beego.Router("/admin/api/orginfo", &OrgAPIController{}, "get:GetOrgInfo")
21 21
 	beego.Router("/admin/api/org/statistics", &OrgAPIController{}, "get:GetOrgDialysisOrderStatistics")
22 22
 
23
+	beego.Router("/admin/api/org/patient", &OrgAPIController{}, "get:GetOrgPatientList")
24
+	beego.Router("/admin/api/org/role", &OrgAPIController{}, "get:GetOrgRoleList")
25
+	beego.Router("/admin/api/org/adminuser", &OrgAPIController{}, "get:GetOrgAdminUser")
26
+	beego.Router("/admin/api/org/zones", &OrgAPIController{}, "get:GetOrgZones")
27
+	beego.Router("/admin/api/org/group", &OrgAPIController{}, "get:GetOrgGroup")
28
+	beego.Router("/admin/api/org/bed", &OrgAPIController{}, "get:GetOrgBed")
29
+
30
+	beego.Router("admin/api/system/user", &SystemApiController{}, "get:GetUserList")
31
+	beego.Router("/admin/api/user/create", &SystemApiController{}, "post:CreateAdminUser")
32
+	beego.Router("/admin/api/user/edit", &SystemApiController{}, "post:ModifyAdminUser")
33
+	beego.Router("/admin/api/user/delete", &SystemApiController{}, "post:DeleteAdminUser")
34
+
35
+	beego.Router("/admin/api/user/init", &SystemApiController{}, "get:GetUserInitData")
36
+	beego.Router("/admin/api/user/followorg", &SystemApiController{}, "get:GetFollowOrg")
37
+	beego.Router("/admin/api/follow", &SystemApiController{}, "post:PostFollowInfo")
38
+
39
+	beego.Router("/admin/api/follow/edit", &SystemApiController{}, "post:ModifyFollowInfo")
40
+	beego.Router("/admin/api/unfollow", &SystemApiController{}, "post:PostUnFollow")
41
+
42
+	beego.Router("/admin/api/user/get", &SystemApiController{}, "get:GetAdminUserById")
43
+	beego.Router("/admin/api/follow/cancel", &SystemApiController{}, "post:CancelFollowInfo")
44
+
23 45
 }

+ 0 - 3
controllers/admin_api_controllers/login_api_controller.go Bestand weergeven

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

+ 135 - 36
controllers/admin_api_controllers/org_api_controller.go Bestand weergeven

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

+ 384 - 0
controllers/admin_api_controllers/system_api_controller.go Bestand weergeven

@@ -0,0 +1,384 @@
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
+	"fmt"
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
+	fmt.Println(FollowOrgs)
115
+	fmt.Println(unFollow)
116
+
117
+	if err == nil {
118
+		this.ServeSuccessJSON(map[string]interface{}{
119
+			"follows":  FollowOrgs,
120
+			"unFollow": unFollow,
121
+		})
122
+	}
123
+}
124
+
125
+func (this *SystemApiController) GetAdminUserById() {
126
+	id, _ := this.GetInt64("id")
127
+	account, err := service.FindAdminById(id)
128
+	if err == nil {
129
+		this.ServeSuccessJSON(map[string]interface{}{
130
+			"account": account,
131
+		})
132
+	}
133
+}
134
+
135
+func (this *SystemApiController) PostFollowInfo() {
136
+	time := time.Now().Unix()
137
+
138
+	var orgFollow []*models.OrgFollow
139
+
140
+	dataBody := make(map[string]interface{}, 0)
141
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
142
+	if err != nil {
143
+		utils.ErrorLog(err.Error())
144
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
145
+		return
146
+	}
147
+
148
+	if dataBody["Follow"] != nil && reflect.TypeOf(dataBody["Follow"]).String() == "[]interface {}" {
149
+		thisFollow, _ := dataBody["Follow"].([]interface{})
150
+		if len(thisFollow) > 0 {
151
+			for _, item := range thisFollow {
152
+				items := item.(map[string]interface{})
153
+				if items["org_id"] == nil || reflect.TypeOf(items["org_id"]).String() != "float64" {
154
+					utils.ErrorLog("org_id")
155
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
156
+					return
157
+				}
158
+				org_id := int64(items["org_id"].(float64))
159
+
160
+				if items["admin_user_id"] == nil || reflect.TypeOf(items["admin_user_id"]).String() != "float64" {
161
+					utils.ErrorLog("admin_user_id")
162
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
163
+					return
164
+				}
165
+				admin_user_id := int64(items["admin_user_id"].(float64))
166
+				follow := &models.OrgFollow{
167
+					Mtime:       time,
168
+					Status:      1,
169
+					Ctime:       time,
170
+					OrgId:       org_id,
171
+					AdminUserId: admin_user_id,
172
+				}
173
+				orgFollow = append(orgFollow, follow)
174
+			}
175
+		}
176
+	}
177
+
178
+	//防止数据冗余,先查出之前被删的数据是否存在,存在则直接改变删除状态,不插入新数据
179
+	for index, follow := range orgFollow {
180
+		info, err := service.FindFollowRecordByID(follow)
181
+
182
+		if err == nil { //存在,则修改删除状态
183
+			orgFollow = append(orgFollow[:index], orgFollow[index+1:]...)
184
+			if info.Status == 0 {
185
+				follow := &models.OrgFollow{
186
+					ID:          info.ID,
187
+					Mtime:       info.Mtime,
188
+					Status:      1,
189
+					Ctime:       info.Ctime,
190
+					OrgId:       info.OrgId,
191
+					AdminUserId: info.AdminUserId,
192
+				}
193
+				service.UpdateFollow(follow)
194
+			}
195
+
196
+		}
197
+	}
198
+
199
+	if len(orgFollow) > 0 {
200
+		errs := service.CreateFollowInfo(orgFollow)
201
+		if errs == nil {
202
+			this.ServeSuccessJSON(map[string]interface{}{
203
+				"msg": "提交成功",
204
+			})
205
+
206
+		}
207
+	} else {
208
+		this.ServeSuccessJSON(map[string]interface{}{
209
+			"msg": "提交成功",
210
+		})
211
+	}
212
+
213
+}
214
+
215
+func (this *SystemApiController) CancelFollowInfo() {
216
+	time := time.Now().Unix()
217
+
218
+	var orgFollow []*models.OrgFollow
219
+
220
+	dataBody := make(map[string]interface{}, 0)
221
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
222
+	if err != nil {
223
+		utils.ErrorLog(err.Error())
224
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
225
+		return
226
+	}
227
+
228
+	if dataBody["Follow"] != nil && reflect.TypeOf(dataBody["Follow"]).String() == "[]interface {}" {
229
+		thisFollow, _ := dataBody["Follow"].([]interface{})
230
+		if len(thisFollow) > 0 {
231
+			for _, item := range thisFollow {
232
+				items := item.(map[string]interface{})
233
+				if items["org_id"] == nil || reflect.TypeOf(items["org_id"]).String() != "float64" {
234
+					utils.ErrorLog("org_id")
235
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
236
+					return
237
+				}
238
+				org_id := int64(items["org_id"].(float64))
239
+
240
+				if items["follow_id"] == nil || reflect.TypeOf(items["follow_id"]).String() != "float64" {
241
+					utils.ErrorLog("follow_id")
242
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
243
+					return
244
+				}
245
+				follow_id := int64(items["follow_id"].(float64))
246
+
247
+				if items["admin_user_id"] == nil || reflect.TypeOf(items["admin_user_id"]).String() != "float64" {
248
+					utils.ErrorLog("admin_user_id")
249
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
250
+					return
251
+				}
252
+				admin_user_id := int64(items["admin_user_id"].(float64))
253
+				follow := &models.OrgFollow{
254
+					ID:          follow_id,
255
+					Mtime:       time,
256
+					Status:      0,
257
+					Ctime:       time,
258
+					OrgId:       org_id,
259
+					AdminUserId: admin_user_id,
260
+				}
261
+				orgFollow = append(orgFollow, follow)
262
+			}
263
+		}
264
+	}
265
+	for _, follow := range orgFollow {
266
+		service.UpdateFollow(follow)
267
+	}
268
+	this.ServeSuccessJSON(map[string]interface{}{
269
+		"follow": orgFollow,
270
+	})
271
+
272
+}
273
+
274
+func (this *SystemApiController) PostUnFollow() {
275
+	org_id, _ := this.GetInt64("org_id")
276
+	admin_user_id, _ := this.GetInt64("admin_user_id")
277
+
278
+	info, _ := service.FindFollowInfoById(org_id, admin_user_id)
279
+	follow := &models.OrgFollow{
280
+		ID:          info.ID,
281
+		Mtime:       time.Now().Unix(),
282
+		Status:      0,
283
+		Ctime:       info.Ctime,
284
+		OrgId:       org_id,
285
+		AdminUserId: info.AdminUserId,
286
+	}
287
+	err := service.UpdateFollow(follow)
288
+	if err == nil {
289
+		this.ServeSuccessJSON(map[string]interface{}{
290
+			"msg": "删除成功",
291
+		})
292
+	}
293
+
294
+}
295
+
296
+func (this *SystemApiController) ModifyFollowInfo() {
297
+	time := time.Now().Unix()
298
+	var orgFollow []*models.OrgFollow
299
+	dataBody := make(map[string]interface{}, 0)
300
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &dataBody)
301
+	if err != nil {
302
+		utils.ErrorLog(err.Error())
303
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
304
+		return
305
+	}
306
+
307
+	if dataBody["Follow"] != nil && reflect.TypeOf(dataBody["Follow"]).String() == "[]interface {}" {
308
+		thisFollow, _ := dataBody["Follow"].([]interface{})
309
+		if len(thisFollow) > 0 {
310
+			for _, item := range thisFollow {
311
+				items := item.(map[string]interface{})
312
+				if items["admin_user_id"] == nil || reflect.TypeOf(items["admin_user_id"]).String() != "float64" {
313
+					utils.ErrorLog("admin_user_id")
314
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
315
+					return
316
+				}
317
+				admin_user_id := int64(items["admin_user_id"].(float64))
318
+
319
+				if items["org_id"] == nil || reflect.TypeOf(items["org_id"]).String() != "float64" {
320
+					utils.ErrorLog("org_id")
321
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
322
+					return
323
+				}
324
+				org_id := int64(items["org_id"].(float64))
325
+
326
+				if items["id"] == nil || reflect.TypeOf(items["id"]).String() != "float64" {
327
+					utils.ErrorLog("id")
328
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
329
+					return
330
+				}
331
+				id := int64(items["id"].(float64))
332
+
333
+				if id == 0 {
334
+					follow := &models.OrgFollow{
335
+						Mtime:       time,
336
+						Status:      1,
337
+						Ctime:       time,
338
+						OrgId:       org_id,
339
+						AdminUserId: admin_user_id,
340
+					}
341
+					orgFollow = append(orgFollow, follow)
342
+				}
343
+			}
344
+		}
345
+	}
346
+
347
+	fmt.Println(orgFollow)
348
+
349
+	//防止数据冗余,先查出之前被删的数据是否存在,存在则直接改变删除状态,不插入新数据
350
+	for index, follow := range orgFollow {
351
+		info, err := service.FindFollowRecordByID(follow)
352
+
353
+		if err == nil { //存在,则修改删除状态
354
+			orgFollow = append(orgFollow[:index], orgFollow[index+1:]...)
355
+			if info.Status == 0 {
356
+				follow := &models.OrgFollow{
357
+					ID:          info.ID,
358
+					Mtime:       info.Mtime,
359
+					Status:      1,
360
+					Ctime:       info.Ctime,
361
+					OrgId:       info.OrgId,
362
+					AdminUserId: info.AdminUserId,
363
+				}
364
+				service.UpdateFollow(follow)
365
+			}
366
+
367
+		}
368
+	}
369
+
370
+	if len(orgFollow) > 0 {
371
+		errs := service.CreateFollowInfo(orgFollow)
372
+		if errs == nil {
373
+			this.ServeSuccessJSON(map[string]interface{}{
374
+				"msg": "提交成功",
375
+			})
376
+
377
+		}
378
+	} else {
379
+		this.ServeSuccessJSON(map[string]interface{}{
380
+			"msg": "提交成功",
381
+		})
382
+	}
383
+
384
+}

+ 8 - 6
enums/error_code.go Bestand weergeven

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

+ 7 - 6
models/admin_models/admin_models.go Bestand weergeven

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

+ 1 - 0
models/admin_user_models.go Bestand weergeven

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

+ 59 - 0
models/org_models.go Bestand weergeven

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

+ 2 - 3
routers/router.go Bestand weergeven

@@ -10,7 +10,7 @@ import (
10 10
 func init() {
11 11
 	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
12 12
 		// AllowAllOrigins:  true,
13
-		AllowOrigins:     []string{"https://xt.kuyicloud.com", "http://localhost:9527", "http://xt.test.shengws.com","https://xt.test.shengws.com", "http://xt.test.sgjyun.com","https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com","https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com"},
13
+		AllowOrigins:     []string{"https://xt.kuyicloud.com", "http://localhost:9527", "http://xt.test.shengws.com", "https://xt.test.shengws.com", "http://xt.test.sgjyun.com", "https://xt.test.sgjyun.com", "http://localhost:8081", "http://localhost:8082", "https://pad.kuyicloud.com", "http://pad.kuyicloud.com", "http://pad.test.sgjyun.com", "https://pad.test.sgjyun.com", "http://admin.xt.test.sgjyun.com", "http://admin.xt.kuyicloud.com", "http://api.szjkhd.com"},
14 14
 		AllowMethods:     []string{"GET", "POST", "PUT", "DELETE", "OPTIONS"},
15 15
 		AllowHeaders:     []string{"Origin", "Authorization", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
16 16
 		ExposeHeaders:    []string{"Content-Length", "Access-Control-Allow-Origin", "Access-Control-Allow-Headers", "Content-Type"},
@@ -19,7 +19,6 @@ func init() {
19 19
 
20 20
 	// beego.Router("/", &controllers.MainController{})
21 21
 
22
-
23 22
 	admin_api.AdminAPIControllersRegisterRouters()
24
-    function_api.FunctionAPIControllersRegisterRouters()
23
+	function_api.FunctionAPIControllersRegisterRouters()
25 24
 }

+ 135 - 64
service/admin_service.go Bestand weergeven

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

+ 0 - 6
service/db.go Bestand weergeven

@@ -96,12 +96,6 @@ func ConnectDB() {
96 96
 
97 97
 }
98 98
 
99
-//func DisconnectDB() {
100
-//	if err := readDb.Close(); nil != err {
101
-//		beego.Error("Disconnect from database failed: " + err.Error())
102
-//	}
103
-//}
104
-
105 99
 func XTReadDB() *gorm.DB {
106 100
 	return readDb
107 101
 }

+ 279 - 106
service/org_service.go Bestand weergeven

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