Browse Source

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

csx 5 years ago
parent
commit
68db1ee84d

+ 184 - 3
controllers/new_mobile_api_controllers/home_api_controller.go View File

@@ -6,7 +6,11 @@ import (
6 6
 	"XT_New/models"
7 7
 	"XT_New/service"
8 8
 	"XT_New/utils"
9
+	"encoding/json"
9 10
 	"github.com/astaxie/beego"
11
+	"io/ioutil"
12
+	"net/http"
13
+	"net/url"
10 14
 	"strconv"
11 15
 	"time"
12 16
 )
@@ -278,6 +282,22 @@ func (this *HomeController) CreateOrg() {
278 282
 		}
279 283
 	}
280 284
 
285
+	var orgs []*models.Org
286
+	vmAdminUser, err := service.GetHomeData(adminUser.Id)
287
+	if err != nil {
288
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
289
+		return
290
+	}
291
+	for _, item := range vmAdminUser.Org {
292
+		orgs = append(orgs, item)
293
+	}
294
+	for _, item := range vmAdminUser.VMApp_Role {
295
+		for _, subItem := range item.Org {
296
+			orgs = append(orgs, subItem)
297
+		}
298
+	}
299
+	orgs = RemoveRepeatedOrgElement(orgs)
300
+
281 301
 	orgType := service.GetOrgTypeByName(org_type)
282 302
 
283 303
 	org := &models.Org{
@@ -318,9 +338,170 @@ func (this *HomeController) CreateOrg() {
318 338
 
319 339
 		//初始化显示配置
320 340
 
321
-		this.ServeSuccessJSON(map[string]interface{}{
322
-			"org": org,
323
-		})
341
+		if len(orgs) == 0 {
342
+			ip := utils.GetIP(this.Ctx.Request)
343
+			ssoDomain := beego.AppConfig.String("sso_domain")
344
+			api := ssoDomain + "/m/login/pwd"
345
+			values := make(url.Values)
346
+			values.Set("mobile", adminUser.Mobile)
347
+			values.Set("password", adminUser.Password)
348
+			values.Set("app_type", "3")
349
+			values.Set("ip", ip)
350
+			resp, requestErr := http.PostForm(api, values)
351
+
352
+			if requestErr != nil {
353
+				utils.ErrorLog("请求SSO登录接口失败: %v", requestErr)
354
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
355
+				return
356
+			}
357
+			defer resp.Body.Close()
358
+			body, ioErr := ioutil.ReadAll(resp.Body)
359
+			if ioErr != nil {
360
+				utils.ErrorLog("SSO登录接口返回数据读取失败: %v", ioErr)
361
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
362
+				return
363
+			}
364
+			var respJSON map[string]interface{}
365
+			utils.InfoLog(string(body))
366
+			if err := json.Unmarshal([]byte(string(body)), &respJSON); err != nil {
367
+				utils.ErrorLog("SSO登录接口返回数据解析JSON失败: %v", err)
368
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
369
+				return
370
+			}
371
+
372
+			if respJSON["state"].(float64) != 1 {
373
+				msg := respJSON["msg"].(string)
374
+				utils.ErrorLog("SSO登录接口请求失败: %v", msg)
375
+				if int(respJSON["code"].(float64)) == 609 {
376
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAccountOrPasswordWrong)
377
+					return
378
+				}
379
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
380
+				return
381
+			} else {
382
+				utils.SuccessLog("SSO登录成功")
383
+				// 下面这几段 Map=>JSON=>Struct 的流程可能会造成速度很慢
384
+				userJSON := respJSON["data"].(map[string]interface{})["admin"].(map[string]interface{})
385
+				userJSONBytes, _ := json.Marshal(userJSON)
386
+				var adminUser models.AdminUser
387
+				if err := json.Unmarshal(userJSONBytes, &adminUser); err != nil {
388
+					utils.ErrorLog("解析管理员失败:%v", err)
389
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
390
+					return
391
+				}
392
+
393
+				var org models.Org
394
+				if respJSON["data"].(map[string]interface{})["org"] != nil {
395
+					orgJSON := respJSON["data"].(map[string]interface{})["org"].(map[string]interface{})
396
+					orgJSONBytes, _ := json.Marshal(orgJSON)
397
+					if err := json.Unmarshal(orgJSONBytes, &org); err != nil {
398
+						utils.ErrorLog("解析机构失败:%v", err)
399
+						this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
400
+						return
401
+					}
402
+				}
403
+
404
+				var app models.OrgApp
405
+
406
+				if respJSON["data"].(map[string]interface{})["app"] != nil {
407
+					appJSON := respJSON["data"].(map[string]interface{})["app"].(map[string]interface{})
408
+					appJSONBytes, _ := json.Marshal(appJSON)
409
+					if err := json.Unmarshal(appJSONBytes, &app); err != nil {
410
+						utils.ErrorLog("解析应用失败:%v", err)
411
+						this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
412
+						return
413
+					}
414
+				}
415
+
416
+				var appRole models.App_Role
417
+
418
+				if respJSON["data"].(map[string]interface{})["app_role"] != nil {
419
+					appRoleJSON := respJSON["data"].(map[string]interface{})["app_role"].(map[string]interface{})
420
+					appRoleJSONBytes, _ := json.Marshal(appRoleJSON)
421
+					if err := json.Unmarshal(appRoleJSONBytes, &appRole); err != nil {
422
+						utils.ErrorLog("解析AppRole失败:%v", err)
423
+						this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
424
+						return
425
+					}
426
+				}
427
+
428
+				var subscibe models.ServeSubscibe
429
+				if respJSON["data"].(map[string]interface{})["subscibe"] != nil {
430
+					subscibeJSON := respJSON["data"].(map[string]interface{})["subscibe"].(map[string]interface{})
431
+					subscibeJSONBytes, _ := json.Marshal(subscibeJSON)
432
+					if err := json.Unmarshal(subscibeJSONBytes, &subscibe); err != nil {
433
+						utils.ErrorLog("解析Subscibe失败:%v", err)
434
+						this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
435
+						return
436
+					}
437
+
438
+				}
439
+
440
+				//service.GetOrgSubscibeState(&subscibe)
441
+				templateInfo, _ := service.GetOrgInfoTemplate(org.Id)
442
+
443
+				mobileAdminUserInfo := &mobile_api_controllers.MobileAdminUserInfo{
444
+					AdminUser:    &adminUser,
445
+					Org:          &org,
446
+					App:          &app,
447
+					AppRole:      &appRole,
448
+					Subscibe:     &subscibe,
449
+					TemplateInfo: &templateInfo,
450
+				}
451
+				this.Ctx.SetCookie("token_cookie", "")
452
+
453
+				//设置seesion
454
+				this.SetSession("mobile_admin_user_info", mobileAdminUserInfo)
455
+
456
+				//设置cookie
457
+				mobile := adminUser.Mobile + "-" + strconv.FormatInt(org.Id, 10) + "-" + strconv.FormatInt(appRole.Id, 10)
458
+				token := utils.GenerateLoginToken(mobile)
459
+				expiration, _ := beego.AppConfig.Int64("mobile_token_expiration_second")
460
+				this.Ctx.SetCookie("token_cookie", token, expiration, "/")
461
+
462
+				var configList interface{}
463
+				var FiledList []*models.FiledConfig
464
+
465
+				if org.Id > 0 {
466
+					configList, _ = service.GetConfigList(org.Id)
467
+					FiledList, _ = service.FindFiledByOrgId(org.Id)
468
+				}
469
+				if len(FiledList) == 0 {
470
+					var err error
471
+					if org.Id > 0 {
472
+						err = service.BatchInsertFiledConfig(org.Id)
473
+						if err == nil {
474
+							FiledList, _ = service.FindFiledByOrgId(org.Id)
475
+						} else {
476
+							utils.ErrorLog("字段批量插入失败:%v", err)
477
+						}
478
+					} else {
479
+						FiledList = make([]*models.FiledConfig, 0)
480
+					}
481
+				}
482
+
483
+				this.ServeSuccessJSON(map[string]interface{}{
484
+					"admin": adminUser,
485
+					"user":  appRole,
486
+					"org":   org,
487
+					"template_info": map[string]interface{}{
488
+						"id":          templateInfo.ID,
489
+						"org_id":      templateInfo.OrgId,
490
+						"template_id": templateInfo.TemplateId,
491
+					},
492
+					"config_list": configList,
493
+					"filed_list":  FiledList,
494
+					"status":      1,
495
+				})
496
+			}
497
+
498
+		} else {
499
+			this.ServeSuccessJSON(map[string]interface{}{
500
+				"org":    org,
501
+				"status": 2,
502
+			})
503
+
504
+		}
324 505
 
325 506
 	}
326 507
 

+ 14 - 5
controllers/new_mobile_api_controllers/new_mobile_api_router_register.go View File

@@ -34,11 +34,20 @@ func NewMobileAPIControllersRegisterRouters() {
34 34
 	beego.Router("/m/api/createOrg", &HomeController{}, "post:CreateOrg")
35 35
 
36 36
 	beego.Router("/m/api/staff", &NewRoleApiController{}, "get:GetAllOrgUser")
37
-	//beego.Router("/m/api/staff/edit", &NewRoleApiController{}, "post:EditAdmin")
38
-	//beego.Router("/m/api/staff/init", &NewRoleApiController{}, "get:GetEditAdminInitData")
39
-	//beego.Router("/m/api/staff/get", &NewRoleApiController{}, "get:GetAdminUserInfo")
40
-	//beego.Router("/m/api/staff/stop", &NewRoleApiController{}, "post:StopAdminUser")
41
-	//beego.Router("/m/api/staff/create", &NewRoleApiController{}, "post:CreateAdminUser")
37
+	beego.Router("/m/api/staff/edit", &NewRoleApiController{}, "post:EditAdmin")
38
+	beego.Router("/m/api/staff/init", &NewRoleApiController{}, "get:GetEditAdminInitData")
39
+	beego.Router("/m/api/staff/get", &NewRoleApiController{}, "get:GetAdminUserInfo")
40
+	beego.Router("/m/api/staff/stop", &NewRoleApiController{}, "post:StopAdminUser")
41
+	beego.Router("/m/api/staff/create", &NewRoleApiController{}, "post:CreateAdminUser")
42
+
43
+	beego.Router("/m/api/role", &NewRoleApiController{}, "get:GetAllOrgRole")
44
+	beego.Router("/m/api/role/edit", &NewRoleApiController{}, "post:EditRole")
45
+	beego.Router("/m/api/role/get", &NewRoleApiController{}, "get:GetOrgRoleInfo")
46
+	beego.Router("/m/api/role/del", &NewRoleApiController{}, "get:DeleteOrgRole")
47
+	beego.Router("/m/api/role/create", &NewRoleApiController{}, "post:CreateRole")
48
+
49
+	beego.Router("/m/api/permission/post", &NewRoleApiController{}, "post:EditRolePermission")
50
+	beego.Router("/m/api/permission", &NewRoleApiController{}, "get:GetAllPermission")
42 51
 
43 52
 	beego.Router("/m/api/patient/getbloodpatientinfo", &NewDialysisApiController{}, "Get:GetBloodPatientInfo")
44 53
 	beego.Router("/m/api/patient/getslowpatientinfo", &NewDialysisApiController{}, "Get:GetSlowPatientInfo")

+ 281 - 47
controllers/new_mobile_api_controllers/new_role_api_controller.go View File

@@ -1,7 +1,11 @@
1 1
 package new_mobile_api_controllers
2 2
 
3 3
 import (
4
+	"XT_New/enums"
5
+	"XT_New/models"
4 6
 	"XT_New/service"
7
+	"strings"
8
+	"time"
5 9
 )
6 10
 
7 11
 type NewRoleApiController struct {
@@ -17,50 +21,280 @@ func (this *NewRoleApiController) GetAllOrgUser() {
17 21
 
18 22
 }
19 23
 
20
-//func (this *NewRoleApiController) EditAdmin() {
21
-//	adminUserInfo := this.GetMobileAdminUserInfo()
22
-//	adminUserId, _ := this.GetInt64("uid")
23
-//	name := this.GetString("name")
24
-//	userTitle := this.GetString("title")
25
-//	roleIds  := this.GetString("role_ids")
26
-//
27
-//	if adminUserId <= 0 || len(name) == 0   || len(roleIds) <= 0 {
28
-//		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
29
-//		return
30
-//	}
31
-//
32
-//	appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserId)
33
-//	if getAppRoleErr != nil {
34
-//		//beego.Error("查询管理员信息时失败:", getAppRoleErr)
35
-//		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
36
-//		return
37
-//	}
38
-//
39
-//	if appRole == nil {
40
-//		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
41
-//		return
42
-//	}
43
-//
44
-//	appRole.UserName = name
45
-//	appRole.UserType = int8(userType)
46
-//	appRole.UserTitle = int8(userTitle)
47
-//	appRole.RoleId = roleId
48
-//	appRole.Intro = intro
49
-//	appRole.ModifyTime = time.Now().Unix()
50
-//	saveErr := service.SaveAppRole(appRole)
51
-//	if saveErr != nil {
52
-//		//beego.Error("修改App_Role失败:", saveErr)
53
-//		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
54
-//
55
-//	} else {
56
-//		this.ServeSuccessJSON(nil)
57
-//	}
58
-//
59
-//
60
-//
61
-//
62
-//
63
-//
64
-//
65
-//
66
-//}
24
+func (this *NewRoleApiController) EditAdmin() {
25
+	adminUserInfo := this.GetMobileAdminUserInfo()
26
+	adminUserId, _ := this.GetInt64("uid")
27
+	name := this.GetString("name")
28
+	userTitle := this.GetString("title")
29
+	roleIds := this.GetString("role_ids")
30
+	if adminUserId <= 0 || len(name) == 0 || len(roleIds) <= 0 {
31
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
32
+		return
33
+	}
34
+	appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserId)
35
+	if getAppRoleErr != nil {
36
+		//beego.Error("查询管理员信息时失败:", getAppRoleErr)
37
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
38
+		return
39
+	}
40
+	if appRole == nil {
41
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
42
+		return
43
+	}
44
+	appRole.UserName = name
45
+	appRole.UserTitleName = userTitle
46
+	appRole.RoleIds = roleIds
47
+	appRole.ModifyTime = time.Now().Unix()
48
+	saveErr := service.SaveAppRole(appRole)
49
+	if saveErr != nil {
50
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
51
+	} else {
52
+		this.ServeSuccessJSON(nil)
53
+	}
54
+}
55
+
56
+func (this *NewRoleApiController) GetEditAdminInitData() {
57
+	adminUserInfo := this.GetMobileAdminUserInfo()
58
+	roles, _ := service.GetAllOrgValidRoles(adminUserInfo.Org.Id)
59
+	this.ServeSuccessJSON(map[string]interface{}{
60
+		"roles": roles,
61
+	})
62
+}
63
+
64
+func (this *NewRoleApiController) GetAdminUserInfo() {
65
+	adminUserInfo := this.GetMobileAdminUserInfo()
66
+	adminUserId, _ := this.GetInt64("uid")
67
+	appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserId)
68
+	if getAppRoleErr != nil {
69
+		//beego.Error("查询管理员信息时失败:", getAppRoleErr)
70
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
71
+		return
72
+	}
73
+	if appRole == nil {
74
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
75
+		return
76
+	}
77
+
78
+	this.ServeSuccessJSON(map[string]interface{}{
79
+		"user_info": appRole,
80
+	})
81
+
82
+}
83
+
84
+func (this *NewRoleApiController) StopAdminUser() {
85
+	adminUserInfo := this.GetMobileAdminUserInfo()
86
+	adminUserId, _ := this.GetInt64("uid")
87
+	appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserId)
88
+	if getAppRoleErr != nil {
89
+		//beego.Error("查询管理员信息时失败:", getAppRoleErr)
90
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
91
+		return
92
+	}
93
+	if appRole == nil {
94
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
95
+		return
96
+	}
97
+
98
+	enable, _ := this.GetBool("enable")
99
+
100
+	if enable {
101
+		appRole.Status = 1
102
+	} else {
103
+		appRole.Status = 0
104
+	}
105
+	appRole.ModifyTime = time.Now().Unix()
106
+	saveErr := service.SaveAppRole(appRole)
107
+	if saveErr != nil {
108
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
109
+	} else {
110
+		this.ServeSuccessJSON(nil)
111
+	}
112
+
113
+}
114
+
115
+func (this *NewRoleApiController) CreateAdminUser() {
116
+	adminUserInfo := this.GetMobileAdminUserInfo()
117
+	mobile := this.GetString("mobile")
118
+	name := this.GetString("name")
119
+	role_ids := this.GetString("role_ids")
120
+	userTitle := this.GetString("title")
121
+
122
+	if len(mobile) == 0 || len(name) == 0 || len(role_ids) <= 0 {
123
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
124
+		return
125
+	}
126
+
127
+	// 判断是否已存在该手机号
128
+	if adminUser, err := service.GetValidAdminUserByMobileReturnErr(mobile); err != nil {
129
+		//beego.Error("查询用户是否已被添加为管理员时失败:", err)
130
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
131
+		return
132
+	} else {
133
+		if adminUser == nil { //新增账号和用户
134
+			_, password, createErr := service.CreateGeneralAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, mobile, name, userTitle, role_ids)
135
+			if createErr != nil {
136
+				//beego.Error("创建管理员失败:", createErr)
137
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
138
+				return
139
+
140
+			} else {
141
+				sendSMSErr := service.SMSSendInviteMobileToJoinOrgAdmin(name, mobile, password)
142
+				if sendSMSErr != nil {
143
+				}
144
+
145
+				this.ServeSuccessJSON(nil)
146
+				return
147
+			}
148
+		} else { //新增用户
149
+			app_role := &models.App_Role{
150
+				AdminUserId:   adminUser.Id,
151
+				OrgId:         adminUserInfo.Org.Id,
152
+				AppId:         adminUserInfo.App.Id,
153
+				Avatar:        "",
154
+				UserName:      name,
155
+				UserTitleName: userTitle,
156
+				Status:        1,
157
+				CreateTime:    time.Now().Unix(),
158
+				ModifyTime:    time.Now().Unix(),
159
+				RoleIds:       role_ids,
160
+			}
161
+
162
+			err := service.CreateUserRole(app_role)
163
+			if err != nil {
164
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
165
+				return
166
+			}
167
+			this.ServeSuccessJSON(nil)
168
+			return
169
+		}
170
+	}
171
+
172
+}
173
+
174
+func (this *NewRoleApiController) GetAllOrgRole() {
175
+	adminUserInfo := this.GetMobileAdminUserInfo()
176
+	roles, err := service.GetAllOrgValidRoles(adminUserInfo.Org.Id)
177
+	if err != nil {
178
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
179
+		return
180
+	} else {
181
+		this.ServeSuccessJSON(map[string]interface{}{
182
+			"roles": roles,
183
+		})
184
+	}
185
+
186
+}
187
+
188
+func (this *NewRoleApiController) EditRole() {
189
+
190
+}
191
+
192
+func (this *NewRoleApiController) GetOrgRoleInfo() {
193
+	role_id, _ := this.GetInt64("id", 0)
194
+	role, err := service.GetRoleByRoleID(role_id)
195
+	if err != nil {
196
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
197
+		return
198
+	} else {
199
+		this.ServeSuccessJSON(map[string]interface{}{
200
+			"role": role,
201
+		})
202
+	}
203
+
204
+}
205
+
206
+func (this *NewRoleApiController) CreateRole() {
207
+	adminUserInfo := this.GetMobileAdminUserInfo()
208
+	role_name := this.GetString("name")
209
+	role_desc := this.GetString("desc")
210
+
211
+	role := &models.Role{
212
+		RoleName:     role_name,
213
+		RoleIntro:    role_desc,
214
+		Creator:      adminUserInfo.AdminUser.Id,
215
+		OrgId:        adminUserInfo.Org.Id,
216
+		AppId:        adminUserInfo.App.Id,
217
+		Status:       1,
218
+		IsSuperAdmin: false,
219
+		CreateTime:   time.Now().Unix(),
220
+		ModifyTime:   time.Now().Unix(),
221
+	}
222
+
223
+	err := service.CreateOrgRole(role)
224
+	if err != nil {
225
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
226
+		return
227
+	} else {
228
+		this.ServeSuccessJSON(map[string]interface{}{
229
+			"role": role,
230
+		})
231
+	}
232
+
233
+}
234
+
235
+func (this *NewRoleApiController) EditRolePermission() {
236
+	role_id, _ := this.GetInt64("id", 0)
237
+	purview_id := this.GetString("purview_id")
238
+	is_open, _ := this.GetInt64("type", 0)
239
+
240
+	permissions, err := service.GetRolePurviewIds(role_id)
241
+	if err != nil {
242
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
243
+		return
244
+	} else {
245
+
246
+		if is_open == 1 { //打开
247
+			permission_arr := strings.Split(permissions, ",")
248
+			permission_arr = append(permission_arr, purview_id)
249
+			permissions = strings.Join(permission_arr, ",")
250
+			//插入数据库
251
+			purview, _ := service.GetRolePurview(role_id)
252
+			purview.PurviewIds = permissions
253
+			err := service.SaveRolePurview(purview)
254
+			if err != nil {
255
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
256
+				return
257
+			}
258
+
259
+			this.ServeSuccessJSON(map[string]interface{}{
260
+				"is_open": 1,
261
+			})
262
+
263
+		} else { //关闭
264
+
265
+			permission_arr := strings.Split(permissions, ",")
266
+			for index, id := range permission_arr {
267
+				if id == purview_id {
268
+					permission_arr = append(permission_arr[:index], permission_arr[index+1:]...)
269
+				}
270
+			}
271
+			purview, _ := service.GetRolePurview(role_id)
272
+			purview.PurviewIds = strings.Join(permission_arr, ",")
273
+
274
+			err := service.SaveRolePurview(purview)
275
+			if err != nil {
276
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
277
+				return
278
+			}
279
+
280
+			this.ServeSuccessJSON(map[string]interface{}{
281
+				"is_open": 0,
282
+			})
283
+
284
+		}
285
+	}
286
+}
287
+
288
+func (this *NewRoleApiController) GetAllPermission() {
289
+	module, _ := this.GetInt64("module")
290
+	parent_id, _ := this.GetInt64("id")
291
+	purviews, _ := service.GetAllPurview(module, parent_id)
292
+	this.ServeSuccessJSON(map[string]interface{}{
293
+		"purviews": purviews,
294
+	})
295
+}
296
+
297
+func (this *NewRoleApiController) DeleteOrgRole() {
298
+	//role_id, _ := this.GetInt64("id", 0)
299
+
300
+}

+ 19 - 18
controllers/role_controller.go View File

@@ -362,7 +362,7 @@ func (this *RoleAPIController) AddAdmin() {
362 362
 	userType, _ := this.GetInt("type")
363 363
 	userTitle, _ := this.GetInt("title")
364 364
 	roleId, _ := this.GetInt64("role")
365
-	intro := this.GetString("intro")
365
+	//intro := this.GetString("intro")
366 366
 
367 367
 	_, titleExist := models.UserTitle[userTitle]
368 368
 	if len(mobile) == 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || !titleExist || roleId <= 0 {
@@ -403,23 +403,24 @@ func (this *RoleAPIController) AddAdmin() {
403 403
 		}
404 404
 	}
405 405
 
406
-	_, password, createErr := service.CreateGeneralAdminUser(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, mobile, name, userType, userTitle, intro, roleId)
407
-	if createErr != nil {
408
-		//beego.Error("创建管理员失败:", createErr)
409
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
410
-		return
411
-
412
-	} else {
413
-		//beego.Trace("用户密码:", password)
414
-		// 发送短信通知这个手机号
415
-		sendSMSErr := service.SMSSendInviteMobileToJoinOrgAdmin(name, mobile, password)
416
-		if sendSMSErr != nil {
417
-			//beego.Error("发送邀请短信失败:%v", sendSMSErr)
418
-		}
419
-
420
-		this.ServeSuccessJSON(nil)
421
-		return
422
-	}
406
+	//TODO
407
+	//_, password, createErr := service.CreateGeneralAdminUser(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, mobile, name, userType, userTitle, intro, roleId)
408
+	//if createErr != nil {
409
+	//	//beego.Error("创建管理员失败:", createErr)
410
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
411
+	//	return
412
+	//
413
+	//} else {
414
+	//	//beego.Trace("用户密码:", password)
415
+	//	// 发送短信通知这个手机号
416
+	//	sendSMSErr := service.SMSSendInviteMobileToJoinOrgAdmin(name, mobile, password)
417
+	//	if sendSMSErr != nil {
418
+	//		//beego.Error("发送邀请短信失败:%v", sendSMSErr)
419
+	//	}
420
+	//
421
+	//	this.ServeSuccessJSON(nil)
422
+	//	return
423
+	//}
423 424
 }
424 425
 
425 426
 // /api/admin/editinit [get]

+ 15 - 13
models/role_models.go View File

@@ -35,19 +35,21 @@ type App_Roles struct {
35 35
 }
36 36
 
37 37
 type App_Role struct {
38
-	Id          int64  `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"`
39
-	AdminUserId int64  `gorm:"column:admin_user_id" json:"admin_user_id"`
40
-	OrgId       int64  `gorm:"column:org_id" json:"org_id"`
41
-	AppId       int64  `gorm:"column:app_id" json:"app_id"`
42
-	RoleId      int64  `gorm:"column:role_id" json:"role_id"`
43
-	Avatar      string `json:"avatar" json:"avatar"`
44
-	UserName    string `gorm:"column:user_name" json:"user_name"`   // 用户名称
45
-	Intro       string `json:"intro"`                               // 简介
46
-	UserType    int8   `gorm:"column:user_type" json:"user_type"`   // 用户类型(1.管理员;2.医生;3.护士;4.运营)
47
-	UserTitle   int8   `gorm:"column:user_title" json:"user_title"` // 用户职称(1.医士;2.医师;3.住院医师;4.主治医师;5.副主任医师;6.主任医师;7.护士;8.护师;9.主管护师;10.副主任护师;11.主任护师;12.运营专员;13.运营主管)
48
-	Status      int8   `json:"status"`                              // 状态 0.无效 1.有效
49
-	CreateTime  int64  `gorm:"column:ctime" json:"ctime"`           // 创建时间
50
-	ModifyTime  int64  `gorm:"column:mtime" json:"mtime"`           // 修改时间
38
+	Id            int64  `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"`
39
+	AdminUserId   int64  `gorm:"column:admin_user_id" json:"admin_user_id"`
40
+	OrgId         int64  `gorm:"column:org_id" json:"org_id"`
41
+	AppId         int64  `gorm:"column:app_id" json:"app_id"`
42
+	RoleId        int64  `gorm:"column:role_id" json:"role_id"`
43
+	Avatar        string `json:"avatar" json:"avatar"`
44
+	UserName      string `gorm:"column:user_name" json:"user_name"`   // 用户名称
45
+	Intro         string `json:"intro"`                               // 简介
46
+	UserType      int8   `gorm:"column:user_type" json:"user_type"`   // 用户类型(1.管理员;2.医生;3.护士;4.运营)
47
+	UserTitle     int8   `gorm:"column:user_title" json:"user_title"` // 用户职称(1.医士;2.医师;3.住院医师;4.主治医师;5.副主任医师;6.主任医师;7.护士;8.护师;9.主管护师;10.副主任护师;11.主任护师;12.运营专员;13.运营主管)
48
+	Status        int8   `json:"status"`                              // 状态 0.无效 1.有效
49
+	CreateTime    int64  `gorm:"column:ctime" json:"ctime"`           // 创建时间
50
+	ModifyTime    int64  `gorm:"column:mtime" json:"mtime"`           // 修改时间UserTitleName string `gorm:"column:user_title_name" json:"user_title_name" form:"user_title_name"`
51
+	UserTitleName string `gorm:"column:user_title_name" json:"user_title_name" form:"user_title_name"`
52
+	RoleIds       string `gorm:"column:role_ids" json:"role_ids" form:"role_ids"`
51 53
 }
52 54
 
53 55
 func (App_Role) TableName() string {

+ 60 - 13
service/role_service.go View File

@@ -259,7 +259,7 @@ func IsUserSuperAdminWithMobile(mobile string) (bool, error) {
259 259
 	return user.IsSuperAdmin, nil
260 260
 }
261 261
 
262
-func CreateGeneralAdminUser(orgID int64, appID int64, mobile string, name string, userType int, userTitle int, intro string, roleID int64) (*models.AdminUser, string, error) {
262
+func CreateGeneralAdminUser(orgID int64, appID int64, mobile string, name string, userTitle string, roleIds string) (*models.AdminUser, string, error) {
263 263
 	now := time.Now().Unix()
264 264
 	tx := writeUserDb.Begin()
265 265
 	var adminUser models.AdminUser
@@ -283,18 +283,16 @@ func CreateGeneralAdminUser(orgID int64, appID int64, mobile string, name string
283 283
 		}
284 284
 	}
285 285
 	app_role := models.App_Role{
286
-		AdminUserId: adminUser.Id,
287
-		OrgId:       orgID,
288
-		AppId:       appID,
289
-		RoleId:      roleID,
290
-		Avatar:      "",
291
-		UserName:    name,
292
-		Intro:       intro,
293
-		UserType:    int8(userType),
294
-		UserTitle:   int8(userTitle),
295
-		Status:      1,
296
-		CreateTime:  now,
297
-		ModifyTime:  now,
286
+		AdminUserId:   adminUser.Id,
287
+		OrgId:         orgID,
288
+		AppId:         appID,
289
+		Avatar:        "",
290
+		UserName:      name,
291
+		UserTitleName: userTitle,
292
+		Status:        1,
293
+		CreateTime:    now,
294
+		ModifyTime:    now,
295
+		RoleIds:       roleIds,
298 296
 	}
299 297
 	if createApp_RoleErr := tx.Create(&app_role).Error; createApp_RoleErr != nil {
300 298
 		tx.Rollback()
@@ -413,3 +411,52 @@ func GetOrgApp(orgID int64, app_type int) (*models.OrgApp, error) {
413 411
 	}
414 412
 	return &apps, nil
415 413
 }
414
+
415
+func GetAllOrgValidRoles(orgID int64) ([]*models.Role, error) {
416
+	var roles []*models.Role
417
+	err := readUserDb.Model(models.Role{}).
418
+		Where("org_id = ? AND status = 1", orgID).
419
+		Order("ctime asc").
420
+		Find(&roles).
421
+		Error
422
+	if err != nil {
423
+		if err == gorm.ErrRecordNotFound {
424
+			return make([]*models.Role, 0), nil
425
+		} else {
426
+			return nil, err
427
+		}
428
+	}
429
+	return roles, nil
430
+}
431
+
432
+func CreateUserRole(userRole *models.App_Role) (err error) {
433
+	err = writeUserDb.Create(&userRole).Error
434
+	return
435
+}
436
+
437
+func CreateOrgRole(role *models.Role) (err error) {
438
+	err = writeUserDb.Create(&role).Error
439
+	return
440
+}
441
+
442
+func GetRolePurview(roleID int64) (*models.RolePurview, error) {
443
+	var rolePurviews *models.RolePurview
444
+	err := readUserDb.Where("role_id = ?", roleID).First(&rolePurviews).Error
445
+	if err != nil {
446
+		if err == gorm.ErrRecordNotFound {
447
+			return nil, nil
448
+		}
449
+	}
450
+	return rolePurviews, nil
451
+}
452
+
453
+func SaveRolePurview(purview *models.RolePurview) (err error) {
454
+	err = writeUserDb.Save(purview).Error
455
+	return
456
+}
457
+
458
+func GetAllPurview(module int64, pid int64) ([]*models.Purview, error) {
459
+	var originPurviews []*models.Purview
460
+	getPurviewErr := readUserDb.Model(models.Purview{}).Where("module = ? AND status = 1 AND parentid = ?", module, pid).Order("listorder asc").Order("id asc").Find(&originPurviews).Error
461
+	return originPurviews, getPurviewErr
462
+}