Browse Source

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

csx 5 years ago
parent
commit
89482a5654

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

@@ -34,20 +34,24 @@ 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
+
37 38
 	beego.Router("/m/api/staff/edit", &NewRoleApiController{}, "post:EditAdmin")
38 39
 	beego.Router("/m/api/staff/init", &NewRoleApiController{}, "get:GetEditAdminInitData")
39 40
 	beego.Router("/m/api/staff/get", &NewRoleApiController{}, "get:GetAdminUserInfo")
40 41
 	beego.Router("/m/api/staff/stop", &NewRoleApiController{}, "post:StopAdminUser")
41 42
 	beego.Router("/m/api/staff/create", &NewRoleApiController{}, "post:CreateAdminUser")
42 43
 
44
+	beego.Router("/m/api/role/addStaff", &NewRoleApiController{}, "post:AddRoleStaff")
45
+
43 46
 	beego.Router("/m/api/role", &NewRoleApiController{}, "get:GetAllOrgRole")
44 47
 	beego.Router("/m/api/role/edit", &NewRoleApiController{}, "post:EditRole")
45 48
 	beego.Router("/m/api/role/get", &NewRoleApiController{}, "get:GetOrgRoleInfo")
46
-	beego.Router("/m/api/role/del", &NewRoleApiController{}, "get:DeleteOrgRole")
49
+	beego.Router("/m/api/role/del", &NewRoleApiController{}, "post:DeleteOrgRole")
47 50
 	beego.Router("/m/api/role/create", &NewRoleApiController{}, "post:CreateRole")
48 51
 
49 52
 	beego.Router("/m/api/permission/post", &NewRoleApiController{}, "post:EditRolePermission")
50 53
 	beego.Router("/m/api/permission", &NewRoleApiController{}, "get:GetAllPermission")
54
+	beego.Router("/m/api/rolepurview", &NewRoleApiController{}, "get:GetRolePurviews")
51 55
 
52 56
 	beego.Router("/m/api/patient/getbloodpatientinfo", &NewDialysisApiController{}, "Get:GetBloodPatientInfo")
53 57
 	beego.Router("/m/api/patient/getslowpatientinfo", &NewDialysisApiController{}, "Get:GetSlowPatientInfo")

+ 110 - 21
controllers/new_mobile_api_controllers/new_role_api_controller.go View File

@@ -4,6 +4,7 @@ import (
4 4
 	"XT_New/enums"
5 5
 	"XT_New/models"
6 6
 	"XT_New/service"
7
+	"strconv"
7 8
 	"strings"
8 9
 	"time"
9 10
 )
@@ -13,12 +14,12 @@ type NewRoleApiController struct {
13 14
 }
14 15
 
15 16
 func (this *NewRoleApiController) GetAllOrgUser() {
17
+
16 18
 	adminUserInfo := this.GetMobileAdminUserInfo()
17
-	viewModels, _, _ := service.GetAdminUsersAndLoginInfo(adminUserInfo.Org.Id, adminUserInfo.App.Id, 1, 10)
19
+	viewModels, _, _ := service.GetAllAdminUsersAndRole(adminUserInfo.Org.Id, adminUserInfo.App.Id, 1, 10)
18 20
 	this.ServeSuccessJSON(map[string]interface{}{
19 21
 		"admins": viewModels,
20 22
 	})
21
-
22 23
 }
23 24
 
24 25
 func (this *NewRoleApiController) EditAdmin() {
@@ -145,26 +146,35 @@ func (this *NewRoleApiController) CreateAdminUser() {
145 146
 				this.ServeSuccessJSON(nil)
146 147
 				return
147 148
 			}
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)
149
+		} else {
150
+
151
+			total, _ := service.FindAdminUserByID(adminUser.Id, adminUserInfo.Org.Id)
152
+
153
+			if total <= 0 {
154
+				//新增用户
155
+				app_role := &models.App_Role{
156
+					AdminUserId:   adminUser.Id,
157
+					OrgId:         adminUserInfo.Org.Id,
158
+					AppId:         adminUserInfo.App.Id,
159
+					Avatar:        "",
160
+					UserName:      name,
161
+					UserTitleName: userTitle,
162
+					Status:        1,
163
+					CreateTime:    time.Now().Unix(),
164
+					ModifyTime:    time.Now().Unix(),
165
+					RoleIds:       role_ids,
166
+				}
167
+				err := service.CreateUserRole(app_role)
168
+				if err != nil {
169
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
170
+					return
171
+				}
172
+				this.ServeSuccessJSON(nil)
173
+			} else {
174
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRepeatCreateStaffException)
165 175
 				return
166 176
 			}
167
-			this.ServeSuccessJSON(nil)
177
+
168 178
 			return
169 179
 		}
170 180
 	}
@@ -186,7 +196,22 @@ func (this *NewRoleApiController) GetAllOrgRole() {
186 196
 }
187 197
 
188 198
 func (this *NewRoleApiController) EditRole() {
199
+	role_id, _ := this.GetInt64("id", 0)
200
+	desc := this.GetString("desc")
201
+
202
+	role, _ := service.GetRoleByRoleID(role_id)
203
+
204
+	role.RoleIntro = desc
205
+	role.ModifyTime = time.Now().Unix()
189 206
 
207
+	err := service.SaveRole(role)
208
+	if err != nil {
209
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
210
+	}
211
+	this.ServeSuccessJSON(map[string]interface{}{
212
+		"role": role,
213
+	})
214
+	return
190 215
 }
191 216
 
192 217
 func (this *NewRoleApiController) GetOrgRoleInfo() {
@@ -295,6 +320,70 @@ func (this *NewRoleApiController) GetAllPermission() {
295 320
 }
296 321
 
297 322
 func (this *NewRoleApiController) DeleteOrgRole() {
298
-	//role_id, _ := this.GetInt64("id", 0)
323
+	roleID, _ := this.GetInt64("role_id")
324
+	enable, _ := this.GetBool("enable")
325
+	if roleID <= 0 {
326
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
327
+		return
328
+	}
329
+
330
+	adminUserInfo := this.GetMobileAdminUserInfo()
331
+
332
+	role, getRoleErr := service.GetRoleByRoleID(roleID)
333
+	if getRoleErr != nil {
334
+		//beego.Error("获取角色失败:", getRoleErr)
335
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
336
+		return
337
+	} else if role == nil {
338
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNotExist)
339
+		return
340
+	}
341
+
342
+	if enable == false {
343
+		if count, _ := service.RoleAdminUserCountTwo(adminUserInfo.Org.Id, adminUserInfo.App.Id, roleID); count != 0 {
344
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCannotRemoveRole)
345
+			return
346
+		}
347
+	}
348
+
349
+	if enable {
350
+		role.Status = 1
351
+	} else {
352
+		role.Status = 2
353
+	}
354
+	role.ModifyTime = time.Now().Unix()
355
+	saveErr := service.ModifyRole(role)
356
+	if saveErr != nil {
357
+		//beego.Error("修改角色失败:", role.Id, saveErr)
358
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
359
+	} else {
360
+		this.ServeSuccessJSON(nil)
361
+	}
362
+
363
+}
364
+
365
+func (this *NewRoleApiController) GetRolePurviews() {
366
+	adminUserInfo := this.GetMobileAdminUserInfo()
367
+	role_id, _ := this.GetInt64("id", 0)
368
+	rolePurview, _ := service.GetRoleAndPurviewById(role_id, adminUserInfo.Org.Id, adminUserInfo.App.Id)
369
+	this.ServeSuccessJSON(map[string]interface{}{
370
+		"role_purview": rolePurview,
371
+	})
372
+}
373
+
374
+func (this *NewRoleApiController) AddRoleStaff() {
375
+	//adminUserInfo := this.GetMobileAdminUserInfo()
376
+	role_id, _ := this.GetInt64("id", 0)
377
+	staff_ids := this.GetString("ids")
378
+	ids := strings.Split(staff_ids, ",")
379
+	for _, item := range ids {
380
+		id, _ := strconv.ParseInt(item, 10, 64)
381
+		role, _ := service.FindAdminUserID(id)
382
+		role.RoleIds = role.RoleIds + "," + strconv.FormatInt(role_id, 10)
383
+		service.SaveAdminUser(&role)
384
+	}
385
+	this.ServeSuccessJSON(map[string]interface{}{
386
+		"msg": "添加成功",
387
+	})
299 388
 
300 389
 }

+ 4 - 0
enums/error_code.go View File

@@ -182,6 +182,8 @@ const ( // ErrorCode
182 182
 	ErrorCodeOrgNoExist = 20032
183 183
 
184 184
 	ErrorCodeRegisterExist = 20033
185
+
186
+	ErrorCodeRepeatCreateStaffException = 20034
185 187
 )
186 188
 
187 189
 var ErrCodeMsgs = map[int]string{
@@ -363,6 +365,8 @@ var ErrCodeMsgs = map[int]string{
363 365
 	ErrorCodeOrgNoExist: "该机构不存在",
364 366
 
365 367
 	ErrorCodeRegisterExist: "该账号已经注册,请登录",
368
+
369
+	ErrorCodeRepeatCreateStaffException: "该员工已经存在无法继续添加",
366 370
 }
367 371
 
368 372
 type SGJError struct {

+ 18 - 14
models/purview_models.go View File

@@ -1,20 +1,22 @@
1 1
 package models
2 2
 
3 3
 type Purview struct {
4
-	Id                  int64  `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"`
5
-	Parentid            int64  `json:"pid"`                                                // 父级ID
6
-	Module              int8   `json:"module"`                                             // 所属应用类型 1.病友经营;2.科普号;3.血透经营;4.慢病管理;
7
-	Name                string `json:"name"`                                               // 规则名称(也是菜单名)
8
-	Urlfor              string `json:"urlfor"`                                             // 规则唯一英文标识,(Controller.Method)
9
-	MenuIconClass       string `gorm:"menu_icon_class" json:"menu_icon_class"`             // 菜单图标的 css 样式
10
-	SuperAdminExclusive int8   `gorm:"super_admin_exclusive" json:"super_admin_exclusive"` // 是否为超级管理员专属 0否1是
11
-	Listorder           int    `json:"-"`                                                  // 排序ID
12
-	Status              int8   `json:"status"`                                             // 状态 0.无效 1.有效 2.禁用
13
-	CreateTime          int64  `gorm:"column:ctime" json:"-"`                              // 创建时间
14
-	ModifyTime          int64  `gorm:"column:mtime" json:"-"`                              // 修改时间
15
-
16
-	Link   string     `gorm:"-" json:"link"`   // urlfor 解析后的链接
17
-	Childs []*Purview `gorm:"-" json:"childs"` // 子节点
4
+	Id                  int64      `gorm:"PRIMARY_KEY;AUTO_INCREMENT" json:"id"`
5
+	Parentid            int64      `json:"pid"`                                                // 父级ID
6
+	Module              int8       `json:"module"`                                             // 所属应用类型 1.病友经营;2.科普号;3.血透经营;4.慢病管理;
7
+	Name                string     `json:"name"`                                               // 规则名称(也是菜单名)
8
+	Urlfor              string     `json:"urlfor"`                                             // 规则唯一英文标识,(Controller.Method)
9
+	MenuIconClass       string     `gorm:"menu_icon_class" json:"menu_icon_class"`             // 菜单图标的 css 样式
10
+	SuperAdminExclusive int8       `gorm:"super_admin_exclusive" json:"super_admin_exclusive"` // 是否为超级管理员专属 0否1是
11
+	Listorder           int        `json:"-"`                                                  // 排序ID
12
+	Status              int8       `json:"status"`                                             // 状态 0.无效 1.有效 2.禁用
13
+	CreateTime          int64      `gorm:"column:ctime" json:"-"`                              // 创建时间
14
+	ModifyTime          int64      `gorm:"column:mtime" json:"-"`                              // 修改时间
15
+	Purview             []*Purview `gorm:"ForeignKey:Parentid;AssociationForeignKey:ID" json:"sub_purview"`
16
+	IconUrl             string     `gorm:"column:icon_url" json:"icon_url" form:"icon_url"`
17
+	Desc                string     `gorm:"column:desc" json:"desc" form:"desc"`
18
+	Link                string     `gorm:"-" json:"link"`   // urlfor 解析后的链接
19
+	Childs              []*Purview `gorm:"-" json:"childs"` // 子节点
18 20
 }
19 21
 
20 22
 func (Purview) TableName() string {
@@ -30,6 +32,8 @@ type RolePurview struct {
30 32
 	Status     int8  // 状态 0.无效 1.有效 2.禁用
31 33
 	CreateTime int64 `gorm:"column:ctime"` // 创建时间
32 34
 	ModifyTime int64 `gorm:"column:mtime"` // 修改时间
35
+
36
+	Role Role `gorm:"ForeignKey:RoleId;AssociationForeignKey:ID" json:"role_info"`
33 37
 }
34 38
 
35 39
 func (RolePurview) TableName() string {

+ 18 - 16
models/role_models.go View File

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

+ 82 - 3
service/role_service.go View File

@@ -1,6 +1,7 @@
1 1
 package service
2 2
 
3 3
 import (
4
+	"database/sql"
4 5
 	"time"
5 6
 
6 7
 	"XT_New/models"
@@ -30,7 +31,7 @@ func GetRoles(orgID int64, appID int64, page int, count int) ([]*models.Role, in
30 31
 
31 32
 func GetAppRole(orgID int64, appID int64, adminUserID int64) (*models.App_Role, error) {
32 33
 	var appRole models.App_Role
33
-	err := readUserDb.Model(models.App_Role{}).Where("org_id = ? and app_id = ? and admin_user_id = ?", orgID, appID, adminUserID).First(&appRole).Error
34
+	err := readUserDb.Model(models.App_Role{}).Preload("AdminUser", "status = 1").Where("org_id = ? and app_id = ? and admin_user_id = ?", orgID, appID, adminUserID).First(&appRole).Error
34 35
 	if err != nil {
35 36
 		if err == gorm.ErrRecordNotFound {
36 37
 			return nil, nil
@@ -416,7 +417,7 @@ func GetAllOrgValidRoles(orgID int64) ([]*models.Role, error) {
416 417
 	var roles []*models.Role
417 418
 	err := readUserDb.Model(models.Role{}).
418 419
 		Where("org_id = ? AND status = 1", orgID).
419
-		Order("ctime asc").
420
+		Order("number asc,ctime").
420 421
 		Find(&roles).
421 422
 		Error
422 423
 	if err != nil {
@@ -426,6 +427,11 @@ func GetAllOrgValidRoles(orgID int64) ([]*models.Role, error) {
426 427
 			return nil, err
427 428
 		}
428 429
 	}
430
+	for _, item := range roles {
431
+		var total int64
432
+		readUserDb.Model(&models.App_Role{}).Where("org_id = ? AND find_in_set(?, role_ids)", orgID, item.Id).Count(&total)
433
+		item.StaffNumber = total
434
+	}
429 435
 	return roles, nil
430 436
 }
431 437
 
@@ -457,6 +463,79 @@ func SaveRolePurview(purview *models.RolePurview) (err error) {
457 463
 
458 464
 func GetAllPurview(module int64, pid int64) ([]*models.Purview, error) {
459 465
 	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
466
+	getPurviewErr := readUserDb.Model(models.Purview{}).Preload("Purview", "status = 1").Where("module = ? AND status = 1 AND parentid = ? AND super_admin_exclusive = 0", module, pid).Order("listorder asc").Order("id asc").Find(&originPurviews).Error
461 467
 	return originPurviews, getPurviewErr
462 468
 }
469
+
470
+type NewAdminUserModel struct {
471
+	ID          int64  `gorm:"id" json:"id"`
472
+	AdminUserId int    `gorm:"admin_user_id" json:"user_id"`
473
+	UserName    string `gorm:"user_name" json:"user_name"`
474
+	UserTitle   int    `gorm:"user_title_name" json:"user_title_name"`
475
+	Ip          string `gorm:"ip" json:"ip"`
476
+	Ctime       int64  `gorm:"ctime" json:"last_login_time"`
477
+	Status      int    `gorm:"status" json:"status"`
478
+	Avatar      string `gorm:"avatar" json:"avatar"`
479
+	RoleIds     string `gorm:"role_ids" json:"role_ids"`
480
+}
481
+
482
+func GetAllAdminUsersAndRole(orgID int64, appID int64, page int, count int) ([]*NewAdminUserModel, int, error) {
483
+	var viewModels []*NewAdminUserModel = make([]*NewAdminUserModel, 0)
484
+	var rows *sql.Rows
485
+	var err error
486
+	rows, err = readUserDb.Raw("SELECT u_a_r.id, u_a_r.admin_user_id, u_a_r.user_name,  u_a_r.user_title, u_a_r.status,u_a_r.avatar,u_a_r.role_ids FROM sgj_user_admin_role AS u_a_r  WHERE org_id = ? AND app_id = ? AND user_type != 1  ORDER BY ctime DESC", orgID, appID).Rows()
487
+	defer rows.Close()
488
+	if err != nil {
489
+		if err == gorm.ErrRecordNotFound {
490
+			return viewModels, 0, nil
491
+		} else {
492
+			return nil, 0, err
493
+		}
494
+	}
495
+	for rows.Next() {
496
+		var viewModel NewAdminUserModel
497
+		readUserDb.ScanRows(rows, &viewModel)
498
+		viewModels = append(viewModels, &viewModel)
499
+	}
500
+	total := 0
501
+	return viewModels, total, nil
502
+}
503
+
504
+func FindAdminUserByID(admin_user_id int64, org_id int64) (total int64, err error) {
505
+	err = readUserDb.Model(&models.App_Role{}).Where("admin_user_id = ? AND org_id = ?", admin_user_id, org_id).Count(&total).Error
506
+	return
507
+}
508
+
509
+func GetRoleAndPurviewById(role_id int64, org_id int64, app_id int64) (rolePurview models.RolePurview, err error) {
510
+	err = readUserDb.Model(&models.RolePurview{}).Preload("Role", "status = 1").Where("role_id = ? AND status = 1 AND org_id = ? AND app_id = ?", role_id, org_id, app_id).First(&rolePurview).Error
511
+	return
512
+}
513
+
514
+func SaveRole(role *models.Role) (err error) {
515
+	err = writeUserDb.Save(&role).Error
516
+	return
517
+}
518
+
519
+// 拥有xx角色的管理员的数量
520
+func RoleAdminUserCountTwo(orgID int64, appID int64, roleID int64) (int, error) {
521
+	var count int
522
+	err := readUserDb.Model(models.App_Role{}).
523
+		Where("org_id = ? AND app_id = ? AND status = 1 AND find_in_set(?, role_ids)", orgID, appID, roleID).
524
+		Count(&count).
525
+		Error
526
+	if err != nil {
527
+		return 0, err
528
+	} else {
529
+		return count, nil
530
+	}
531
+}
532
+
533
+func FindAdminUserID(id int64) (role models.App_Role, err error) {
534
+	err = readUserDb.Model(&models.App_Role{}).Where("id = ?", id).First(&role).Error
535
+	return
536
+}
537
+
538
+func SaveAdminUser(role *models.App_Role) (err error) {
539
+	err = writeUserDb.Save(&role).Error
540
+	return
541
+}