Quellcode durchsuchen

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

XMLWAN vor 4 Jahren
Ursprung
Commit
504ffccc6c

+ 61 - 58
controllers/base_api_controller.go Datei anzeigen

@@ -2,6 +2,8 @@ package controllers
2 2
 
3 3
 import (
4 4
 	"XT_New/enums"
5
+	"XT_New/models"
6
+	"XT_New/service"
5 7
 )
6 8
 
7 9
 type BaseAPIController struct {
@@ -60,37 +62,36 @@ type BaseAuthAPIController struct {
60 62
 func (this *BaseAuthAPIController) Prepare() {
61 63
 	this.BaseAPIController.Prepare()
62 64
 	if this.GetAdminUserInfo() == nil {
63
-		//var userAdmin models.AdminUser
64
-		//userAdmin.Id = 380
65
-		//userAdmin.Mobile = "13532250447"
66
-		//userAdmin.IsSuperAdmin = true
67
-		//userAdmin.Status = 1
68
-		//userAdmin.CreateTime = 1530786071
69
-		//userAdmin.ModifyTime = 1530786071
70
-		//var subscibe models.ServeSubscibe
71
-		//subscibe.ID = 1
72
-		//subscibe.OrgId = 4
73
-		//subscibe.PeriodStart = 1538035409
74
-		//subscibe.PeriodEnd = 1569571409
75
-		//subscibe.State = 1
76
-		//subscibe.Status = 1
77
-		//subscibe.CreatedTime = 1538035409
78
-		//subscibe.UpdatedTime = 1538035409
79
-		//subscibes := make(map[int64]*models.ServeSubscibe, 0)
80
-		//subscibes[4] = &subscibe
81
-		//
82
-		//var template models.GobalTemplate
83
-		//template.TemplateId = 2
84
-		//
85
-		//var adminUserInfo service.AdminUserInfo
86
-		//adminUserInfo.CurrentOrgId = 4
87
-		//adminUserInfo.CurrentAppId = 5
88
-		//adminUserInfo.AdminUser = &userAdmin
89
-		//adminUserInfo.Subscibes = subscibes
90
-		//this.SetSession("admin_user_info", &adminUserInfo)
91
-
92
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
93
-		this.StopRun()
65
+		var userAdmin models.AdminUser
66
+		//userAdmin.Id = 400
67
+		//userAdmin.Mobile = "13535547901"
68
+
69
+		userAdmin.Id = 597
70
+		userAdmin.Mobile = "19874122664"
71
+		userAdmin.IsSuperAdmin = false
72
+		userAdmin.Status = 1
73
+		userAdmin.CreateTime = 1530786071
74
+		userAdmin.ModifyTime = 1530786071
75
+		var subscibe models.ServeSubscibe
76
+		subscibe.ID = 1
77
+		subscibe.OrgId = 12
78
+		subscibe.PeriodStart = 1538035409
79
+		subscibe.PeriodEnd = 1569571409
80
+		subscibe.State = 1
81
+		subscibe.Status = 1
82
+		subscibe.CreatedTime = 1538035409
83
+		subscibe.UpdatedTime = 1538035409
84
+		subscibes := make(map[int64]*models.ServeSubscibe, 0)
85
+		subscibes[4] = &subscibe
86
+		var adminUserInfo service.AdminUserInfo
87
+		adminUserInfo.CurrentOrgId = 12
88
+		adminUserInfo.CurrentAppId = 18
89
+		adminUserInfo.AdminUser = &userAdmin
90
+		adminUserInfo.Subscibes = subscibes
91
+		this.SetSession("admin_user_info", &adminUserInfo)
92
+
93
+		//this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
94
+		//this.StopRun()
94 95
 	}
95 96
 
96 97
 	//if this.Ctx.Request.Method != "GET" {
@@ -176,33 +177,35 @@ type BaseServeAPIController struct {
176 177
 func (this *BaseServeAPIController) Prepare() {
177 178
 	this.BaseAPIController.Prepare()
178 179
 	if this.GetAdminUserInfo() == nil {
179
-		//var userAdmin models.AdminUser
180
-		//userAdmin.Id = 380
181
-		//userAdmin.Mobile = "13532250447"
182
-		//userAdmin.IsSuperAdmin = true
183
-		//userAdmin.Status = 1
184
-		//userAdmin.CreateTime = 1530786071
185
-		//userAdmin.ModifyTime = 1530786071
186
-		//var subscibe models.ServeSubscibe
187
-		//subscibe.ID = 1
188
-		//subscibe.OrgId = 4
189
-		//subscibe.PeriodStart = 1538035409
190
-		//subscibe.PeriodEnd = 1569571409
191
-		//subscibe.State = 1
192
-		//subscibe.Status = 1
193
-		//subscibe.CreatedTime = 1538035409
194
-		//subscibe.UpdatedTime = 1538035409
195
-		//subscibes := make(map[int64]*models.ServeSubscibe, 0)
196
-		//subscibes[4] = &subscibe
197
-		//var adminUserInfo service.AdminUserInfo
198
-		//adminUserInfo.CurrentOrgId = 4
199
-		//adminUserInfo.CurrentAppId = 5
200
-		//adminUserInfo.AdminUser = &userAdmin
201
-		//adminUserInfo.Subscibes = subscibes
202
-		//this.SetSession("admin_user_info", &adminUserInfo)
203
-
204
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
205
-		this.StopRun()
180
+		var userAdmin models.AdminUser
181
+		//userAdmin.Id = 400
182
+		//userAdmin.Mobile = "13535547901"
183
+		userAdmin.Id = 597
184
+		userAdmin.Mobile = "19874122664"
185
+		userAdmin.IsSuperAdmin = false
186
+		userAdmin.Status = 1
187
+		userAdmin.CreateTime = 1530786071
188
+		userAdmin.ModifyTime = 1530786071
189
+		var subscibe models.ServeSubscibe
190
+		subscibe.ID = 1
191
+		subscibe.OrgId = 12
192
+		subscibe.PeriodStart = 1538035409
193
+		subscibe.PeriodEnd = 1569571409
194
+		subscibe.State = 1
195
+		subscibe.Status = 1
196
+		subscibe.CreatedTime = 1538035409
197
+		subscibe.UpdatedTime = 1538035409
198
+		subscibes := make(map[int64]*models.ServeSubscibe, 0)
199
+		subscibes[4] = &subscibe
200
+		var adminUserInfo service.AdminUserInfo
201
+		adminUserInfo.CurrentOrgId = 12
202
+		adminUserInfo.CurrentAppId = 18
203
+		adminUserInfo.AdminUser = &userAdmin
204
+		adminUserInfo.Subscibes = subscibes
205
+		this.SetSession("admin_user_info", &adminUserInfo)
206
+
207
+		//this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
208
+		//this.StopRun()
206 209
 	}
207 210
 }
208 211
 

+ 0 - 1
controllers/mobile_api_controllers/login_api_controller.go Datei anzeigen

@@ -129,7 +129,6 @@ func (this *LoginAPIController) LoginByPwd() {
129 129
 
130 130
 		//service.GetOrgSubscibeState(&subscibe)
131 131
 		templateInfo, _ := service.GetOrgInfoTemplate(org.Id)
132
-
133 132
 		mobileAdminUserInfo := &MobileAdminUserInfo{
134 133
 			AdminUser:    &adminUser,
135 134
 			Org:          &org,

+ 10 - 0
controllers/mobile_api_controllers/mobile_api_base_controller.go Datei anzeigen

@@ -66,6 +66,16 @@ func (this *MobileBaseAPIAuthController) Prepare() {
66 66
 	//		this.StopRun()
67 67
 	//	}
68 68
 	//}
69
+	if adminUserInfo.AppRole != nil {
70
+		app_role, _ := service.FindAppRoleById(adminUserInfo.AppRole.Id)
71
+		if app_role.Status != 1 {
72
+			this.DelSession("mobile_admin_user_info")
73
+			this.Ctx.SetCookie("token_cookie", "")
74
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeForbidden)
75
+			this.StopRun()
76
+		}
77
+
78
+	}
69 79
 
70 80
 	if this.Ctx.Request.Header.Get("Permission") == "1" {
71 81
 		if !adminUserInfo.AdminUser.IsSuperAdmin || adminUserInfo.AdminUser.Id != adminUserInfo.Org.Creator {

+ 25 - 7
controllers/new_mobile_api_controllers/home_api_controller.go Datei anzeigen

@@ -12,6 +12,7 @@ import (
12 12
 	"net/http"
13 13
 	"net/url"
14 14
 	"strconv"
15
+	"strings"
15 16
 	"time"
16 17
 )
17 18
 
@@ -39,6 +40,21 @@ func (this *HomeController) GetHomeData() {
39 40
 		}
40 41
 		orgs = RemoveRepeatedOrgElement(orgs)
41 42
 
43
+		var isSubSuperAdmin bool = false
44
+
45
+		app_role, _ := service.GetAppRoleById(adminUserInfo.AppRole.Id)
46
+		role_ids := strings.Split(app_role.RoleIds, ",")
47
+
48
+		if adminUserInfo.AdminUser.Id != adminUserInfo.Org.Creator {
49
+			for _, item := range role_ids {
50
+				id, _ := strconv.ParseInt(item, 10, 64)
51
+				role, _ := service.GetRoleByRoleID(id)
52
+				if role.IsSystem == 1 && role.RoleName == "子管理员" {
53
+					isSubSuperAdmin = true
54
+				}
55
+			}
56
+		}
57
+
42 58
 		apps, err := service.GetAllApp(adminUserInfo.Org.Id)
43 59
 		if err != nil {
44 60
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
@@ -52,10 +68,11 @@ func (this *HomeController) GetHomeData() {
52 68
 		}
53 69
 
54 70
 		this.ServeSuccessJSON(map[string]interface{}{
55
-			"orgs":        orgs,
56
-			"apps":        apps,
57
-			"banners":     banners,
58
-			"isCreateOrg": true,
71
+			"orgs":            orgs,
72
+			"apps":            apps,
73
+			"banners":         banners,
74
+			"isCreateOrg":     true,
75
+			"isSubSuperAdmin": isSubSuperAdmin,
59 76
 		})
60 77
 	} else {
61 78
 		apps, err := service.GetAllApp(0)
@@ -70,9 +87,10 @@ func (this *HomeController) GetHomeData() {
70 87
 		}
71 88
 
72 89
 		this.ServeSuccessJSON(map[string]interface{}{
73
-			"isCreateOrg": false,
74
-			"apps":        apps,
75
-			"banners":     banners,
90
+			"isCreateOrg":     false,
91
+			"apps":            apps,
92
+			"banners":         banners,
93
+			"isSubSuperAdmin": false,
76 94
 		})
77 95
 	}
78 96
 

+ 57 - 6
controllers/new_mobile_api_controllers/new_role_api_controller.go Datei anzeigen

@@ -15,11 +15,25 @@ type NewRoleApiController struct {
15 15
 }
16 16
 
17 17
 func (this *NewRoleApiController) GetAllOrgUser() {
18
-
19 18
 	adminUserInfo := this.GetMobileAdminUserInfo()
20
-	viewModels, _, _ := service.GetAllAdminUsersAndRole(adminUserInfo.Org.Id, adminUserInfo.App.Id, 1, 10)
19
+	var isSubSuperAdmin bool = false
20
+	app_role, _ := service.GetAppRoleById(adminUserInfo.AppRole.Id)
21
+	role_ids := strings.Split(app_role.RoleIds, ",")
22
+
23
+	if adminUserInfo.AdminUser.Id != adminUserInfo.Org.Creator {
24
+		for _, item := range role_ids {
25
+			id, _ := strconv.ParseInt(item, 10, 64)
26
+			role, _ := service.GetRoleByRoleID(id)
27
+			if role.IsSystem == 1 && role.RoleName == "子管理员" {
28
+				isSubSuperAdmin = true
29
+			}
30
+		}
31
+	}
32
+	viewModels, _, _ := service.GetAllAdminUsersAndRole(adminUserInfo.Org.Id, adminUserInfo.App.Id, 1, 100)
21 33
 	this.ServeSuccessJSON(map[string]interface{}{
22
-		"admins": viewModels,
34
+		"admins":          viewModels,
35
+		"isSubSuperAdmin": isSubSuperAdmin,
36
+		"org_creator":     adminUserInfo.Org.Creator,
23 37
 	})
24 38
 }
25 39
 
@@ -29,6 +43,11 @@ func (this *NewRoleApiController) EditAdmin() {
29 43
 	name := this.GetString("name")
30 44
 	userTitle := this.GetString("title")
31 45
 	roleIds := this.GetString("role_ids")
46
+	user_type, _ := this.GetInt64("user_type", 0)
47
+	user_title, _ := this.GetInt64("user_title", 0)
48
+
49
+	//roleIds := this.GetString("role_ids")
50
+
32 51
 	if adminUserId <= 0 || len(name) == 0 || len(roleIds) <= 0 {
33 52
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
34 53
 		return
@@ -47,6 +66,8 @@ func (this *NewRoleApiController) EditAdmin() {
47 66
 	appRole.UserTitleName = userTitle
48 67
 	appRole.RoleIds = roleIds
49 68
 	appRole.ModifyTime = time.Now().Unix()
69
+	appRole.UserType = int8(user_type)
70
+	appRole.UserTitle = int8(user_title)
50 71
 	saveErr := service.SaveAppRole(appRole)
51 72
 	if saveErr != nil {
52 73
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
@@ -57,7 +78,8 @@ func (this *NewRoleApiController) EditAdmin() {
57 78
 
58 79
 func (this *NewRoleApiController) GetEditAdminInitData() {
59 80
 	adminUserInfo := this.GetMobileAdminUserInfo()
60
-	roles, _ := service.GetAllOrgValidRoles(adminUserInfo.Org.Id)
81
+
82
+	roles, _ := service.GetNewAllOrgValidRoles(adminUserInfo.Org.Id)
61 83
 	this.ServeSuccessJSON(map[string]interface{}{
62 84
 		"roles": roles,
63 85
 	})
@@ -66,6 +88,7 @@ func (this *NewRoleApiController) GetEditAdminInitData() {
66 88
 func (this *NewRoleApiController) GetAdminUserInfo() {
67 89
 	adminUserInfo := this.GetMobileAdminUserInfo()
68 90
 	adminUserId, _ := this.GetInt64("uid")
91
+
69 92
 	appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserId)
70 93
 	if getAppRoleErr != nil {
71 94
 		//beego.Error("查询管理员信息时失败:", getAppRoleErr)
@@ -120,6 +143,8 @@ func (this *NewRoleApiController) CreateAdminUser() {
120 143
 	name := this.GetString("name")
121 144
 	role_ids := this.GetString("role_ids")
122 145
 	userTitle := this.GetString("title")
146
+	user_type, _ := this.GetInt("user_type", 0)
147
+	user_title, _ := this.GetInt("user_title", 0)
123 148
 
124 149
 	if len(mobile) == 0 || len(name) == 0 || len(role_ids) <= 0 {
125 150
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
@@ -133,7 +158,7 @@ func (this *NewRoleApiController) CreateAdminUser() {
133 158
 		return
134 159
 	} else {
135 160
 		if adminUser == nil { //新增账号和用户
136
-			_, password, createErr := service.CreateGeneralAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, mobile, name, userTitle, role_ids)
161
+			_, password, createErr := service.CreateGeneralAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, mobile, name, userTitle, role_ids, user_type, user_title)
137 162
 			if createErr != nil {
138 163
 				//beego.Error("创建管理员失败:", createErr)
139 164
 				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
@@ -160,6 +185,8 @@ func (this *NewRoleApiController) CreateAdminUser() {
160 185
 					Avatar:        "",
161 186
 					UserName:      name,
162 187
 					UserTitleName: userTitle,
188
+					UserTitle:     int8(user_title),
189
+					UserType:      int8(user_type),
163 190
 					Status:        1,
164 191
 					CreateTime:    time.Now().Unix(),
165 192
 					ModifyTime:    time.Now().Unix(),
@@ -184,7 +211,24 @@ func (this *NewRoleApiController) CreateAdminUser() {
184 211
 
185 212
 func (this *NewRoleApiController) GetAllOrgRole() {
186 213
 	adminUserInfo := this.GetMobileAdminUserInfo()
187
-	roles, err := service.GetAllOrgValidRoles(adminUserInfo.Org.Id)
214
+
215
+	var isSubSuperAdmin bool = false
216
+
217
+	app_role, _ := service.GetAppRoleById(adminUserInfo.AppRole.Id)
218
+	role_ids := strings.Split(app_role.RoleIds, ",")
219
+
220
+	if adminUserInfo.AdminUser.Id != adminUserInfo.Org.Creator {
221
+		for _, item := range role_ids {
222
+			id, _ := strconv.ParseInt(item, 10, 64)
223
+			role, _ := service.GetRoleByRoleID(id)
224
+			if role.IsSystem == 1 && role.RoleName == "子管理员" {
225
+				isSubSuperAdmin = true
226
+			}
227
+		}
228
+	}
229
+	fmt.Println(isSubSuperAdmin)
230
+
231
+	roles, err := service.GetAllOrgValidRoles(adminUserInfo.Org.Id, isSubSuperAdmin)
188 232
 	if err != nil {
189 233
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
190 234
 		return
@@ -234,6 +278,13 @@ func (this *NewRoleApiController) CreateRole() {
234 278
 	role_name := this.GetString("name")
235 279
 	role_desc := this.GetString("desc")
236 280
 
281
+	total := service.FindRoleRecordByRoleName(role_name, adminUserInfo.Org.Id)
282
+	if total > 0 {
283
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNameIsExist)
284
+		return
285
+
286
+	}
287
+
237 288
 	role := &models.Role{
238 289
 		RoleName:     role_name,
239 290
 		RoleIntro:    role_desc,

+ 2 - 2
controllers/new_mobile_api_controllers/role.json Datei anzeigen

@@ -15,7 +15,7 @@
15 15
         "role_introduction": "医生角色能够进行建立患者档案,制定和调整患者透析治疗方案,定期评价病人的透析质量等",
16 16
         "is_super_admin": false,
17 17
         "status": 1,
18
-        "is_system": 1,
18
+        "is_system": 2,
19 19
         "number": 9998,
20 20
         "purview_ids": "71,72,70,74,75,73,127,128,48,52,110,93,121,122,124,125,120,101,100,102,156,157,158,159,15571,72,70,74,75,73,127,128,48,52,110,93,121,122,124,125,120,101,100,102,156,157,158,159,155",
21 21
         "func_ids": "1,2,3,4,5,6,7,8,9,10,11,12,24,25,26,27,28,29,30,31,32,33"
@@ -27,7 +27,7 @@
27 27
         "role_introduction": "护士角色能够进行病人透析管理,以及医院的感染控制与消毒记录等",
28 28
         "is_super_admin": false,
29 29
         "status": 1,
30
-        "is_system": 1,
30
+        "is_system": 3,
31 31
         "number": 9997,
32 32
         "purview_ids": "74,75,73,48,52,110,93,121,122,124,125,120",
33 33
         "func_ids": "7,8,10,11,12,13,14,16,17,19,21,22,24,25,27,28"

+ 270 - 143
controllers/role_controller.go Datei anzeigen

@@ -31,6 +31,13 @@ func RoleAPIControllerRegistRouters() {
31 31
 
32 32
 	beego.Router("/api/admin/specialpermission/initdata", &RoleAPIController{}, "get:SpecialPermissionInitData")
33 33
 	beego.Router("/api/admin/specialpermission/dialysisrecord/submit", &RoleAPIController{}, "post:SubmitDialysisRecordPermission")
34
+
35
+	beego.Router("/api/roles/list", &RoleAPIController{}, "get:GetAllOrgRole")
36
+	beego.Router("/api/staff", &RoleAPIController{}, "get:GetAllOrgUser")
37
+	beego.Router("/api/role/addStaff", &RoleAPIController{}, "post:AddRoleStaff")
38
+
39
+	beego.Router("/api/role/staff", &RoleAPIController{}, "get:GetRoleStaff")
40
+
34 41
 }
35 42
 
36 43
 type RoleAPIController struct {
@@ -43,15 +50,14 @@ func (this *RoleAPIController) GetRoles() {
43 50
 	page, _ := this.GetInt("page")
44 51
 	adminUserInfo := this.GetAdminUserInfo()
45 52
 	//beego.Alert(adminUserInfo.AdminUser)
46
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
47
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
48
-		return
49
-	}
50
-
53
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
54
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
55
+	//	return
56
+	//}
51 57
 	if page <= 0 {
52 58
 		page = 1
53 59
 	}
54
-	roles, total, getRoleErr := service.GetRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, page, 10)
60
+	roles, total, getRoleErr := service.GetRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, page, 100)
55 61
 	if getRoleErr != nil {
56 62
 		//beego.Error("获取角色列表失败:", getRoleErr)
57 63
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
@@ -74,11 +80,16 @@ func (this *RoleAPIController) CreateRole() {
74 80
 		return
75 81
 	}
76 82
 	adminUserInfo := this.GetAdminUserInfo()
77
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
78
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
83
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
84
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
85
+	//	return
86
+	//}
87
+
88
+	total := service.FindRoleRecordByRoleName(name, adminUserInfo.CurrentOrgId)
89
+	if total > 0 {
90
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNameIsExist)
79 91
 		return
80 92
 	}
81
-
82 93
 	role, createErr := service.CreateRole(adminUserInfo.AdminUser.Id, adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, name, intro)
83 94
 	if createErr != nil {
84 95
 		//beego.Error("创建角色失败:", createErr)
@@ -105,11 +116,11 @@ func (this *RoleAPIController) ModifyRole() {
105 116
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
106 117
 		return
107 118
 	}
108
-	adminUserInfo := this.GetAdminUserInfo()
109
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
110
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
111
-		return
112
-	}
119
+	//adminUserInfo := this.GetAdminUserInfo()
120
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
121
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
122
+	//	return
123
+	//}
113 124
 
114 125
 	role, getRoleErr := service.GetRoleByRoleID(roleID)
115 126
 	if getRoleErr != nil {
@@ -145,10 +156,10 @@ func (this *RoleAPIController) ModifyRoleStatus() {
145 156
 	}
146 157
 
147 158
 	adminUserInfo := this.GetAdminUserInfo()
148
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
149
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
150
-		return
151
-	}
159
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
160
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
161
+	//	return
162
+	//}
152 163
 
153 164
 	role, getRoleErr := service.GetRoleByRoleID(roleID)
154 165
 	if getRoleErr != nil {
@@ -185,11 +196,11 @@ func (this *RoleAPIController) ModifyRoleStatus() {
185 196
 // /role/purview/editinit [get]
186 197
 // @param role_id:int
187 198
 func (this *RoleAPIController) EditPurviewInitData() {
188
-	adminUserInfo := this.GetAdminUserInfo()
189
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
190
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
191
-		return
192
-	}
199
+	//adminUserInfo := this.GetAdminUserInfo()
200
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
201
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
202
+	//	return
203
+	//}
193 204
 
194 205
 	roleId, _ := this.GetInt64("role_id")
195 206
 	if roleId <= 0 {
@@ -220,10 +231,10 @@ func (this *RoleAPIController) EditPurviewInitData() {
220 231
 // @param purview_ids:string
221 232
 func (this *RoleAPIController) EditPurview() {
222 233
 	adminUserInfo := this.GetAdminUserInfo()
223
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
224
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
225
-		return
226
-	}
234
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
235
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
236
+	//	return
237
+	//}
227 238
 	roleId, _ := this.GetInt64("role_id")
228 239
 	purviewIds := this.GetString("purview_ids")
229 240
 	if roleId <= 0 {
@@ -275,24 +286,38 @@ func (this *RoleAPIController) EditPurview() {
275 286
 // /api/adminmain [get]
276 287
 func (this *RoleAPIController) AdminMainView() {
277 288
 	adminUserInfo := this.GetAdminUserInfo()
278
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
279
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
280
-		return
289
+
290
+	//org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
291
+
292
+	var isSubSuperAdmin bool = false
293
+	adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
294
+
295
+	//app_role, _ := service.GetAppRoleById(adminUserInfo.)
296
+	role_ids := strings.Split(adminUserRole.RoleIds, ",")
297
+
298
+	org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
299
+
300
+	if adminUserInfo.AdminUser.Id != org.Creator {
301
+		for _, item := range role_ids {
302
+			id, _ := strconv.ParseInt(item, 10, 64)
303
+			role, _ := service.GetRoleByRoleID(id)
304
+			if role.IsSystem == 1 && role.RoleName == "子管理员" {
305
+				isSubSuperAdmin = true
306
+			}
307
+		}
281 308
 	}
282 309
 
283
-	viewModels, total, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 10)
310
+	viewModels, _, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
284 311
 	if getAdminsErr != nil {
285 312
 		//beego.Error("获取管理员列表失败:", getAdminsErr)
286 313
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
287 314
 		return
288 315
 	}
289 316
 
290
-	existRoleCount, _ := service.GetValidRoleCount(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
291
-
292 317
 	this.ServeSuccessJSON(map[string]interface{}{
293
-		"admins":        viewModels,
294
-		"total_count":   total,
295
-		"is_exist_role": existRoleCount > 0,
318
+		"admins":          viewModels,
319
+		"org":             org,
320
+		"isSubSuperAdmin": isSubSuperAdmin,
296 321
 	})
297 322
 }
298 323
 
@@ -300,13 +325,13 @@ func (this *RoleAPIController) AdminMainView() {
300 325
 // @param page?:int
301 326
 func (this *RoleAPIController) Admins() {
302 327
 	adminUserInfo := this.GetAdminUserInfo()
303
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
304
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
305
-		return
306
-	}
328
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
329
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
330
+	//	return
331
+	//}
307 332
 
308 333
 	page, _ := this.GetInt("page")
309
-	viewModels, total, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, page, 10)
334
+	viewModels, total, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, page, 100)
310 335
 	if getAdminsErr != nil {
311 336
 		//beego.Error("获取管理员列表失败:", getAdminsErr)
312 337
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
@@ -321,9 +346,27 @@ func (this *RoleAPIController) Admins() {
321 346
 // /api/admin/addinit [get]
322 347
 func (this *RoleAPIController) AddAdminInitData() {
323 348
 	adminUserInfo := this.GetAdminUserInfo()
324
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
325
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
326
-		return
349
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
350
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
351
+	//	return
352
+	//}
353
+
354
+	var isSubSuperAdmin bool = false
355
+	adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
356
+
357
+	//app_role, _ := service.GetAppRoleById(adminUserInfo.)
358
+	role_ids := strings.Split(adminUserRole.RoleIds, ",")
359
+
360
+	org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
361
+
362
+	if adminUserInfo.AdminUser.Id != org.Creator {
363
+		for _, item := range role_ids {
364
+			id, _ := strconv.ParseInt(item, 10, 64)
365
+			role, _ := service.GetRoleByRoleID(id)
366
+			if role.IsSystem == 1 && role.RoleName == "子管理员" {
367
+				isSubSuperAdmin = true
368
+			}
369
+		}
327 370
 	}
328 371
 
329 372
 	roles, getRoleErr := service.GetAllValidRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
@@ -338,8 +381,10 @@ func (this *RoleAPIController) AddAdminInitData() {
338 381
 	qntoken, _ := redisClient.Get("qn_token").Result()
339 382
 
340 383
 	this.ServeSuccessJSON(map[string]interface{}{
341
-		"roles":   roles,
342
-		"qntoken": qntoken,
384
+		"roles":           roles,
385
+		"qntoken":         qntoken,
386
+		"isSubSuperAdmin": isSubSuperAdmin,
387
+		"org":             org,
343 388
 	})
344 389
 }
345 390
 
@@ -352,85 +397,85 @@ func (this *RoleAPIController) AddAdminInitData() {
352 397
 // @param intro?:string
353 398
 func (this *RoleAPIController) AddAdmin() {
354 399
 	adminUserInfo := this.GetAdminUserInfo()
355
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
356
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
357
-		return
358
-	}
400
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
401
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
402
+	//	return
403
+	//}
359 404
 
360 405
 	mobile := this.GetString("mobile")
361 406
 	name := this.GetString("name")
362 407
 	userType, _ := this.GetInt("type")
363 408
 	userTitle, _ := this.GetInt("title")
364
-	roleId, _ := this.GetInt64("role")
365
-	//intro := this.GetString("intro")
409
+	roleIds := this.GetString("role")
410
+	user_title_name := this.GetString("user_title_name")
366 411
 
367
-	_, titleExist := models.UserTitle[userTitle]
368
-	if len(mobile) == 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || !titleExist || roleId <= 0 {
412
+	if len(mobile) == 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || len(roleIds) <= 0 {
369 413
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
370 414
 		return
371 415
 	}
372 416
 
373
-	isRoleExist, getRoleErr := service.IsRoleExist(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, roleId)
374
-	if getRoleErr != nil {
375
-		//beego.Error("查询角色是否存在时失败:", getRoleErr)
376
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
377
-		return
378
-	}
379
-	if !isRoleExist {
380
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNotExist)
381
-		return
382
-	}
383
-
384
-	// 判断该应用是否已存在该手机号
385
-	if isMobileDidUsed, err := service.IsMobileDidUsedAtApp(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, mobile); err != nil {
417
+	// 判断是否已存在该手机号
418
+	if adminUser, err := service.GetValidAdminUserByMobileReturnErr(mobile); err != nil {
386 419
 		//beego.Error("查询用户是否已被添加为管理员时失败:", err)
387 420
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
388 421
 		return
389 422
 	} else {
390
-		if isMobileDidUsed {
391
-			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMobileDidUsedInApp)
392
-			return
393
-		}
394
-	}
423
+		if adminUser == nil { //新增账号和用户
424
+			_, password, createErr := service.CreateGeneralAdminUser(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, mobile, name, user_title_name, roleIds, userType, userTitle)
425
+			if createErr != nil {
426
+				//beego.Error("创建管理员失败:", createErr)
427
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
428
+				return
429
+
430
+			} else {
431
+				sendSMSErr := service.SMSSendInviteMobileToJoinOrgAdmin(name, mobile, password)
432
+				if sendSMSErr != nil {
433
+				}
434
+
435
+				this.ServeSuccessJSON(nil)
436
+				return
437
+			}
438
+		} else {
439
+
440
+			total, _ := service.FindAdminUserByID(adminUser.Id, adminUserInfo.CurrentOrgId)
441
+
442
+			if total <= 0 {
443
+				//新增用户
444
+				app_role := &models.App_Role{
445
+					AdminUserId:   adminUser.Id,
446
+					OrgId:         adminUserInfo.CurrentOrgId,
447
+					AppId:         adminUserInfo.CurrentAppId,
448
+					Avatar:        "",
449
+					UserName:      name,
450
+					UserTitleName: user_title_name,
451
+					Status:        1,
452
+					UserType:      int8(userType),
453
+					UserTitle:     int8(userTitle),
454
+					CreateTime:    time.Now().Unix(),
455
+					ModifyTime:    time.Now().Unix(),
456
+					RoleIds:       roleIds,
457
+				}
458
+				err := service.CreateUserRole(app_role)
459
+				if err != nil {
460
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
461
+					return
462
+				}
463
+				this.ServeSuccessJSON(nil)
464
+			} else {
465
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRepeatCreateStaffException)
466
+				return
467
+			}
395 468
 
396
-	if isSuperAdmin, err := service.IsUserSuperAdminWithMobile(mobile); err != nil {
397
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMobileNotExit)
398
-		return
399
-	} else {
400
-		if isSuperAdmin {
401
-			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleMobileIsSuperAdmin)
402 469
 			return
403 470
 		}
404 471
 	}
405 472
 
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
-	//}
424 473
 }
425 474
 
426 475
 // /api/admin/editinit [get]
427 476
 // @param uid:int
428 477
 func (this *RoleAPIController) EditAdminInitData() {
429 478
 	adminUserInfo := this.GetAdminUserInfo()
430
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
431
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
432
-		return
433
-	}
434 479
 
435 480
 	admin_user_id, _ := this.GetInt64("uid")
436 481
 	if admin_user_id <= 0 {
@@ -438,13 +483,13 @@ func (this *RoleAPIController) EditAdminInitData() {
438 483
 		return
439 484
 	}
440 485
 
441
-	adminUserViewModel, getInfoErr := service.GetGeneralAdminUser(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, admin_user_id)
442
-	if getInfoErr != nil {
443
-		//beego.Error("获取管理员信息失败:", getInfoErr)
486
+	appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, admin_user_id)
487
+	if getAppRoleErr != nil {
488
+		//beego.Error("查询管理员信息时失败:", getAppRoleErr)
444 489
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
445 490
 		return
446 491
 	}
447
-	if adminUserViewModel == nil {
492
+	if appRole == nil {
448 493
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
449 494
 		return
450 495
 	}
@@ -456,14 +501,33 @@ func (this *RoleAPIController) EditAdminInitData() {
456 501
 		return
457 502
 	}
458 503
 
504
+	var isSubSuperAdmin bool = false
505
+	adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
506
+
507
+	//app_role, _ := service.GetAppRoleById(adminUserInfo.)
508
+	role_ids := strings.Split(adminUserRole.RoleIds, ",")
509
+
510
+	org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
511
+
512
+	if adminUserInfo.AdminUser.Id != org.Creator {
513
+		for _, item := range role_ids {
514
+			id, _ := strconv.ParseInt(item, 10, 64)
515
+			role, _ := service.GetRoleByRoleID(id)
516
+			if role.IsSystem == 1 && role.RoleName == "子管理员" {
517
+				isSubSuperAdmin = true
518
+			}
519
+		}
520
+	}
521
+
459 522
 	redisClient := service.RedisClient()
460 523
 	defer redisClient.Close()
461 524
 	qntoken, _ := redisClient.Get("qn_token").Result()
462 525
 
463 526
 	this.ServeSuccessJSON(map[string]interface{}{
464
-		"admin":   adminUserViewModel,
465
-		"roles":   roles,
466
-		"qntoken": qntoken,
527
+		"admin":           appRole,
528
+		"roles":           roles,
529
+		"qntoken":         qntoken,
530
+		"isSubSuperAdmin": isSubSuperAdmin,
467 531
 	})
468 532
 }
469 533
 
@@ -476,20 +540,21 @@ func (this *RoleAPIController) EditAdminInitData() {
476 540
 // @param intro?:string
477 541
 func (this *RoleAPIController) EditAdmin() {
478 542
 	adminUserInfo := this.GetAdminUserInfo()
479
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
480
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
481
-		return
482
-	}
543
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
544
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
545
+	//	return
546
+	//}
483 547
 
484 548
 	adminUserId, _ := this.GetInt64("uid")
485 549
 	name := this.GetString("name")
486 550
 	userType, _ := this.GetInt("type")
487 551
 	userTitle, _ := this.GetInt("title")
488
-	roleId, _ := this.GetInt64("role")
552
+	roleIds := this.GetString("role")
489 553
 	intro := this.GetString("intro")
554
+	user_title_name := this.GetString("user_title_name")
490 555
 
491 556
 	_, titleExist := models.UserTitle[userTitle]
492
-	if adminUserId <= 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || !titleExist || roleId <= 0 {
557
+	if adminUserId <= 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || !titleExist || len(roleIds) <= 0 {
493 558
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
494 559
 		return
495 560
 	}
@@ -505,22 +570,12 @@ func (this *RoleAPIController) EditAdmin() {
505 570
 		return
506 571
 	}
507 572
 
508
-	isRoleExist, getRoleErr := service.IsRoleExist(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, roleId)
509
-	if getRoleErr != nil {
510
-		//beego.Error("查询角色是否存在时失败:", getRoleErr)
511
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
512
-		return
513
-	}
514
-	if !isRoleExist {
515
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNotExist)
516
-		return
517
-	}
518
-
519 573
 	appRole.UserName = name
520 574
 	appRole.UserType = int8(userType)
521 575
 	appRole.UserTitle = int8(userTitle)
522
-	appRole.RoleId = roleId
576
+	appRole.RoleIds = roleIds
523 577
 	appRole.Intro = intro
578
+	appRole.UserTitleName = user_title_name
524 579
 	appRole.ModifyTime = time.Now().Unix()
525 580
 	saveErr := service.SaveAppRole(appRole)
526 581
 	if saveErr != nil {
@@ -537,10 +592,10 @@ func (this *RoleAPIController) EditAdmin() {
537 592
 // @param enable:bool
538 593
 func (this *RoleAPIController) AdminSetStatus() {
539 594
 	adminUserInfo := this.GetAdminUserInfo()
540
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
541
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
542
-		return
543
-	}
595
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
596
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
597
+	//	return
598
+	//}
544 599
 
545 600
 	userID, _ := this.GetInt64("uid")
546 601
 	if userID <= 0 {
@@ -558,12 +613,6 @@ func (this *RoleAPIController) AdminSetStatus() {
558 613
 	}
559 614
 
560 615
 	enable, _ := this.GetBool("enable")
561
-	if enable == true {
562
-		if roleEnable, _ := service.IsRoleExist(appRole.OrgId, appRole.AppId, appRole.RoleId); roleEnable == false {
563
-			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNotExist)
564
-			return
565
-		}
566
-	}
567 616
 
568 617
 	if enable {
569 618
 		appRole.Status = 1
@@ -584,10 +633,10 @@ func (this *RoleAPIController) AdminSetStatus() {
584 633
 // /api/admin/specialpermission/initdata [get]
585 634
 func (this *RoleAPIController) SpecialPermissionInitData() {
586 635
 	adminUserInfo := this.GetAdminUserInfo()
587
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
588
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
589
-		return
590
-	}
636
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
637
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
638
+	//	return
639
+	//}
591 640
 
592 641
 	adminUsers, getAdminUsersErr := service.GetAllGeneralAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
593 642
 	if getAdminUsersErr != nil {
@@ -613,10 +662,10 @@ func (this *RoleAPIController) SpecialPermissionInitData() {
613 662
 // @param ids:string ("1,2,5")
614 663
 func (this *RoleAPIController) SubmitDialysisRecordPermission() {
615 664
 	adminUserInfo := this.GetAdminUserInfo()
616
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
617
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
618
-		return
619
-	}
665
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
666
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
667
+	//	return
668
+	//}
620 669
 
621 670
 	idsString := this.GetString("ids")
622 671
 	if len(idsString) == 0 {
@@ -712,3 +761,81 @@ func (this *RoleAPIController) SubmitDialysisRecordPermission() {
712 761
 	}
713 762
 
714 763
 }
764
+
765
+func (this *RoleAPIController) GetAllOrgRole() {
766
+	adminUserInfo := this.GetAdminUserInfo()
767
+
768
+	var isSubSuperAdmin bool = false
769
+	adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
770
+
771
+	//app_role, _ := service.GetAppRoleById(adminUserInfo.)
772
+	role_ids := strings.Split(adminUserRole.RoleIds, ",")
773
+
774
+	org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
775
+
776
+	if adminUserInfo.AdminUser.Id != org.Creator {
777
+		for _, item := range role_ids {
778
+			id, _ := strconv.ParseInt(item, 10, 64)
779
+			role, _ := service.GetRoleByRoleID(id)
780
+			if role.IsSystem == 1 && role.RoleName == "子管理员" {
781
+				isSubSuperAdmin = true
782
+			}
783
+		}
784
+	}
785
+
786
+	roles, err := service.GetAllOrgValidRoles(adminUserInfo.CurrentOrgId, isSubSuperAdmin)
787
+	if err != nil {
788
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
789
+		return
790
+	} else {
791
+		this.ServeSuccessJSON(map[string]interface{}{
792
+			"roles": roles,
793
+		})
794
+	}
795
+
796
+}
797
+
798
+func (this *RoleAPIController) GetAllOrgUser() {
799
+	adminUserInfo := this.GetAdminUserInfo()
800
+	org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
801
+	viewModels, _, _ := service.GetAllAdminUsersAndRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
802
+	this.ServeSuccessJSON(map[string]interface{}{
803
+		"admins": viewModels,
804
+		"org":    org,
805
+	})
806
+}
807
+
808
+func (this *RoleAPIController) AddRoleStaff() {
809
+	//adminUserInfo := this.GetMobileAdminUserInfo()
810
+	role_id, _ := this.GetInt64("id", 0)
811
+	staff_ids := this.GetString("ids")
812
+	ids := strings.Split(staff_ids, ",")
813
+	for _, item := range ids {
814
+		id, _ := strconv.ParseInt(item, 10, 64)
815
+		role, _ := service.FindAdminUserID(id)
816
+		role.RoleIds = role.RoleIds + "," + strconv.FormatInt(role_id, 10)
817
+		service.SaveAdminUser(&role)
818
+	}
819
+	this.ServeSuccessJSON(map[string]interface{}{
820
+		"msg": "添加成功",
821
+	})
822
+
823
+}
824
+
825
+func (this *RoleAPIController) GetRoleStaff() {
826
+	adminUserInfo := this.GetAdminUserInfo()
827
+
828
+	viewModels, _, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
829
+	if getAdminsErr != nil {
830
+		//beego.Error("获取管理员列表失败:", getAdminsErr)
831
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
832
+		return
833
+	}
834
+	org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
835
+
836
+	this.ServeSuccessJSON(map[string]interface{}{
837
+		"admins": viewModels,
838
+		"org":    org,
839
+	})
840
+
841
+}

+ 7 - 0
enums/error_code.go Datei anzeigen

@@ -184,6 +184,9 @@ const ( // ErrorCode
184 184
 	ErrorCodeRegisterExist = 20033
185 185
 
186 186
 	ErrorCodeRepeatCreateStaffException = 20034
187
+
188
+	ErrorCodeForbidden       = 20035
189
+	ErrorCodeRoleNameIsExist = 20036
187 190
 )
188 191
 
189 192
 var ErrCodeMsgs = map[int]string{
@@ -367,6 +370,10 @@ var ErrCodeMsgs = map[int]string{
367 370
 	ErrorCodeRegisterExist: "该账号已经注册,请登录",
368 371
 
369 372
 	ErrorCodeRepeatCreateStaffException: "该员工已经存在无法继续添加",
373
+
374
+	ErrorCodeForbidden: "你已经被管理员禁用,无法使用该系统",
375
+
376
+	ErrorCodeRoleNameIsExist: "该角色已经不存在",
370 377
 }
371 378
 
372 379
 type SGJError struct {

+ 5 - 3
models/role_models.go Datei anzeigen

@@ -54,9 +54,11 @@ type App_Role struct {
54 54
 	UserTitleName string    `gorm:"column:user_title_name" json:"user_title_name" form:"user_title_name"`
55 55
 	RoleIds       string    `gorm:"column:role_ids" json:"role_ids" form:"role_ids"`
56 56
 	AdminUser     AdminUser `gorm:"ForeignKey:ID;AssociationForeignKey:AdminUserId" json:"admin"`
57
-	Message       string    `gorm:"column:message" json:"message" form:"message"`
58
-	Sex           int64     `gorm:"column:sex" json:"sex" form:"sex"`
59
-	Birthday      int64     `gorm:"column:birthday" json:"birthday" form:"birthday"`
57
+	//AdminUser     AdminUser `gorm:"ForeignKey:ID;AssociationForeignKey:AdminUserId" json:"admin"`
58
+	IsSubSuperAdmin bool   `gorm:"-" json:"is_sub_super_admin" form:"is_sub_super_admin"`
59
+	Message         string `gorm:"column:message" json:"message" form:"message"`
60
+	Sex             int64  `gorm:"column:sex" json:"sex" form:"sex"`
61
+	Birthday        int64  `gorm:"column:birthday" json:"birthday" form:"birthday"`
60 62
 }
61 63
 
62 64
 func (App_Role) TableName() string {

+ 2 - 2
models/vm_models.go Datei anzeigen

@@ -309,8 +309,8 @@ type VMUserRoleAndPurview struct {
309 309
 	Ctime            int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
310 310
 	Mtime            int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
311 311
 	Number           int64  `gorm:"column:number" json:"number" form:"number"`
312
-	PurviewIds       string `gorm:"column:-" json:"purview_ids" form:"purview_ids"`
313
-	FuncIds          string `gorm:"column:-" json:"func_ids" form:"func_ids"`
312
+	PurviewIds       string `gorm:"-" json:"purview_ids" form:"purview_ids"`
313
+	FuncIds          string `gorm:"-" json:"func_ids" form:"func_ids"`
314 314
 	IsSystem         int64  `gorm:"column:is_system" json:"is_system" form:"is_system"`
315 315
 }
316 316
 

+ 13 - 0
service/login_service.go Datei anzeigen

@@ -231,3 +231,16 @@ func IsMobileRegister(mobile string) bool {
231 231
 	}
232 232
 	return count > 0
233 233
 }
234
+
235
+func FindAppRoleById(id int64) (*models.App_Role, error) {
236
+	var model models.App_Role
237
+	err := readUserDb.Model(&models.App_Role{}).Where("id = ? ", id).First(&model).Error
238
+	if err != nil {
239
+		if err == gorm.ErrRecordNotFound {
240
+			return nil, nil
241
+		} else {
242
+			return nil, err
243
+		}
244
+	}
245
+	return &model, nil
246
+}

+ 93 - 9
service/role_service.go Datei anzeigen

@@ -2,6 +2,9 @@ package service
2 2
 
3 3
 import (
4 4
 	"database/sql"
5
+	"fmt"
6
+	"strconv"
7
+	"strings"
5 8
 	"time"
6 9
 
7 10
 	"XT_New/models"
@@ -39,6 +42,17 @@ func GetAppRole(orgID int64, appID int64, adminUserID int64) (*models.App_Role,
39 42
 			return nil, err
40 43
 		}
41 44
 	}
45
+
46
+	role_ids := strings.Split(appRole.RoleIds, ",")
47
+
48
+	for _, item := range role_ids {
49
+		id, _ := strconv.ParseInt(item, 10, 64)
50
+		role, _ := GetRoleByRoleID(id)
51
+		if role.IsSystem == 1 && role.RoleName == "子管理员" {
52
+			appRole.IsSubSuperAdmin = true
53
+		}
54
+	}
55
+
42 56
 	return &appRole, nil
43 57
 }
44 58
 
@@ -108,9 +122,11 @@ type AdminUserManageViewModel struct {
108 122
 	Ctime       int64  `gorm:"ctime" json:"last_login_time"`
109 123
 	Status      int    `gorm:"status" json:"status"`
110 124
 	Avatar      string `gorm:"avatar" json:"avatar"`
111
-
125
+	RoleIds     string `gorm:"role_ids" json:"role_ids"`
112 126
 	// LastLoginTimeStr string `gorm:"-" json:"last_login_time_formatted"`
113
-	TitleName string `gorm:"-" json:"title_name"`
127
+	TitleName       string `gorm:"-" json:"title_name"`
128
+	IsSubSuperAdmin bool   `gorm:"-" json:"is_sub_super_admin"`
129
+	//mobile          string `gorm:"-" json:"mobile"`
114 130
 }
115 131
 
116 132
 func GetAdminUsersAndLoginInfo(orgID int64, appID int64, page int, count int) ([]*AdminUserManageViewModel, int, error) {
@@ -121,7 +137,7 @@ func GetAdminUsersAndLoginInfo(orgID int64, appID int64, page int, count int) ([
121 137
 		page = 1
122 138
 	}
123 139
 	var viewModels []*AdminUserManageViewModel = make([]*AdminUserManageViewModel, 0)
124
-	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,u_a_r.avatar 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()
140
+	rows, err := readUserDb.Raw("SELECT u_a_r.admin_user_id, u_a_r.user_name, u_a_r.user_title, u_l.ip, u_l.ctime, u_a_r.status,u_a_r.avatar,u_a_r.role_ids FROM sgj_user_admin_role AS u_a_r  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 = ? AND user_type != 1 GROUP BY u_a_r.admin_user_id LIMIT ? OFFSET ?;", orgID, appID, orgID, appID, count, (page-1)*count).Rows()
125 141
 	defer rows.Close()
126 142
 	if err != nil {
127 143
 		if err == gorm.ErrRecordNotFound {
@@ -143,8 +159,30 @@ func GetAdminUsersAndLoginInfo(orgID int64, appID int64, page int, count int) ([
143 159
 		// }
144 160
 		viewModels = append(viewModels, &viewModel)
145 161
 	}
162
+
163
+	for _, item := range viewModels {
164
+		ids := strings.Split(item.RoleIds, ",")
165
+		for _, id := range ids {
166
+			id, _ := strconv.ParseInt(id, 10, 64)
167
+			role, _ := GetRoleByRoleID(id)
168
+			if role.IsSystem == 1 && role.RoleName == "子管理员" {
169
+				item.IsSubSuperAdmin = true
170
+			}
171
+
172
+			if len(item.RoleName) == 0 {
173
+				item.RoleName = role.RoleName
174
+			} else {
175
+				item.RoleName = item.RoleName + "," + role.RoleName
176
+			}
177
+		}
178
+
179
+		//admin, _ := GetAdminUserByUserID(int64(item.AdminUserId))
180
+		//item.mobile = admin.Mobile
181
+
182
+	}
183
+
146 184
 	total := 0
147
-	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)
185
+	//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)
148 186
 	return viewModels, total, nil
149 187
 }
150 188
 
@@ -260,7 +298,7 @@ func IsUserSuperAdminWithMobile(mobile string) (bool, error) {
260 298
 	return user.IsSuperAdmin, nil
261 299
 }
262 300
 
263
-func CreateGeneralAdminUser(orgID int64, appID int64, mobile string, name string, userTitle string, roleIds string) (*models.AdminUser, string, error) {
301
+func CreateGeneralAdminUser(orgID int64, appID int64, mobile string, name string, userTitle string, roleIds string, user_type int, user_title int) (*models.AdminUser, string, error) {
264 302
 	now := time.Now().Unix()
265 303
 	tx := writeUserDb.Begin()
266 304
 	var adminUser models.AdminUser
@@ -290,6 +328,8 @@ func CreateGeneralAdminUser(orgID int64, appID int64, mobile string, name string
290 328
 		Avatar:        "",
291 329
 		UserName:      name,
292 330
 		UserTitleName: userTitle,
331
+		UserTitle:     int8(user_title),
332
+		UserType:      int8(user_type),
293 333
 		Status:        1,
294 334
 		CreateTime:    now,
295 335
 		ModifyTime:    now,
@@ -413,10 +453,14 @@ func GetOrgApp(orgID int64, app_type int) (*models.OrgApp, error) {
413 453
 	return &apps, nil
414 454
 }
415 455
 
416
-func GetAllOrgValidRoles(orgID int64) ([]*models.Role, error) {
456
+func GetAllOrgValidRoles(orgID int64, isSubSuperAdmin bool) ([]*models.Role, error) {
417 457
 	var roles []*models.Role
418
-	err := readUserDb.Model(models.Role{}).
419
-		Where("org_id = ? AND status = 1", orgID).
458
+	db := readUserDb.Model(models.Org{})
459
+	if isSubSuperAdmin {
460
+		fmt.Println("1111")
461
+		db = db.Where("role_name != '子管理员' AND is_system  != 1")
462
+	}
463
+	err := db.Where("org_id = ? AND status = 1", orgID).
420 464
 		Order("number desc,ctime").
421 465
 		Find(&roles).
422 466
 		Error
@@ -490,13 +534,14 @@ type NewAdminUserModel struct {
490 534
 	Status      int    `gorm:"status" json:"status"`
491 535
 	Avatar      string `gorm:"avatar" json:"avatar"`
492 536
 	RoleIds     string `gorm:"role_ids" json:"role_ids"`
537
+	IsSubAdmin  bool   `gorm:"-" json:"is_sub_admin"`
493 538
 }
494 539
 
495 540
 func GetAllAdminUsersAndRole(orgID int64, appID int64, page int, count int) ([]*NewAdminUserModel, int, error) {
496 541
 	var viewModels []*NewAdminUserModel = make([]*NewAdminUserModel, 0)
497 542
 	var rows *sql.Rows
498 543
 	var err error
499
-	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()
544
+	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 = ? ORDER BY ctime DESC", orgID, appID).Rows()
500 545
 	defer rows.Close()
501 546
 	if err != nil {
502 547
 		if err == gorm.ErrRecordNotFound {
@@ -510,6 +555,18 @@ func GetAllAdminUsersAndRole(orgID int64, appID int64, page int, count int) ([]*
510 555
 		readUserDb.ScanRows(rows, &viewModel)
511 556
 		viewModels = append(viewModels, &viewModel)
512 557
 	}
558
+
559
+	for _, items := range viewModels {
560
+		ids := strings.Split(items.RoleIds, ",")
561
+		for _, ids := range ids {
562
+			id, _ := strconv.ParseInt(ids, 10, 64)
563
+			role, _ := GetRoleByRoleID(id)
564
+			if role.IsSystem == 1 && role.RoleName == "子管理员" {
565
+				items.IsSubAdmin = true
566
+			}
567
+		}
568
+	}
569
+
513 570
 	total := 0
514 571
 	return viewModels, total, nil
515 572
 }
@@ -598,3 +655,30 @@ func FindErrorMsgByStr(str string) (string, error) {
598 655
 	return purview.ErrorMsg, err
599 656
 
600 657
 }
658
+
659
+func GetNewAllOrgValidRoles(orgID int64) ([]*models.Role, error) {
660
+	var roles []*models.Role
661
+	db := readUserDb.Model(models.Org{})
662
+	err := db.Where("org_id = ? AND status = 1", orgID).
663
+		Order("number desc,ctime").
664
+		Find(&roles).
665
+		Error
666
+	if err != nil {
667
+		if err == gorm.ErrRecordNotFound {
668
+			return make([]*models.Role, 0), nil
669
+		} else {
670
+			return nil, err
671
+		}
672
+	}
673
+	for _, item := range roles {
674
+		var total int64
675
+		readUserDb.Model(&models.App_Role{}).Where("org_id = ? AND find_in_set(?, role_ids)", orgID, item.Id).Count(&total)
676
+		item.StaffNumber = total
677
+	}
678
+	return roles, nil
679
+}
680
+
681
+func FindRoleRecordByRoleName(name string, org_id int64) (total int64) {
682
+	readUserDb.Model(&models.Role{}).Where("status = 1 AND role_name = ? AND org_id = ?", name, org_id).Count(&total)
683
+	return
684
+}