Browse Source

添加权限管理接口

庄逸洲 5 years ago
parent
commit
434a7076f0

controllers/admin/admin_controller.go → controllers/admin_user/admin_controller.go View File

1
-package admin
1
+package admin_user
2
 
2
 
3
 import (
3
 import (
4
 	base_ctl "SCRM/controllers"
4
 	base_ctl "SCRM/controllers"

controllers/admin/router_collector.go → controllers/admin_user/router_collector.go View File

1
-package admin
1
+package admin_user
2
 
2
 
3
 func RegisterRouters() {
3
 func RegisterRouters() {
4
 	AdminCtlRegistRouters()
4
 	AdminCtlRegistRouters()

+ 336 - 0
controllers/role/admin_controller.go View File

1
+package role
2
+
3
+import (
4
+	base_ctl "SCRM/controllers"
5
+	"SCRM/enums"
6
+	"SCRM/models"
7
+	"SCRM/service"
8
+	base_service "SCRM/service"
9
+	"SCRM/service/role_service"
10
+	"time"
11
+
12
+	"github.com/astaxie/beego"
13
+)
14
+
15
+func AdminCtlRegistRouters() {
16
+	beego.Router("/api/adminmain", &AdminAPIController{}, "get:AdminMainView")
17
+	beego.Router("/api/admins", &AdminAPIController{}, "get:Admins")
18
+	beego.Router("/api/admin/addinit", &AdminAPIController{}, "get:AddAdminInitData")
19
+	beego.Router("/api/admin/add", &AdminAPIController{}, "post:AddAdmin")
20
+	beego.Router("/api/admin/editinit", &AdminAPIController{}, "get:EditAdminInitData")
21
+	beego.Router("/api/admin/edit", &AdminAPIController{}, "post:EditAdmin")
22
+	beego.Router("/api/admin/setstatus", &AdminAPIController{}, "post:AdminSetStatus")
23
+}
24
+
25
+type AdminAPIController struct {
26
+	base_ctl.BaseAuthAPIController
27
+}
28
+
29
+// /api/adminmain [get]
30
+func (this *AdminAPIController) AdminMainView() {
31
+	adminUserInfo := this.GetAdminUserInfo()
32
+	if adminUserInfo.AdminUser.IsSuperAdmin == false {
33
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
34
+		return
35
+	}
36
+
37
+	viewModels, total, getAdminsErr := role_service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 10)
38
+	if getAdminsErr != nil {
39
+		//beego.Error("获取管理员列表失败:", getAdminsErr)
40
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
41
+		return
42
+	}
43
+
44
+	existRoleCount, _ := role_service.GetValidRoleCount(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
45
+
46
+	this.ServeSuccessJSON(map[string]interface{}{
47
+		"admins":        viewModels,
48
+		"total_count":   total,
49
+		"is_exist_role": existRoleCount > 0,
50
+	})
51
+}
52
+
53
+// /api/admins [get]
54
+// @param page?:int
55
+func (this *AdminAPIController) Admins() {
56
+	adminUserInfo := this.GetAdminUserInfo()
57
+	if adminUserInfo.AdminUser.IsSuperAdmin == false {
58
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
59
+		return
60
+	}
61
+
62
+	page, _ := this.GetInt("page")
63
+	viewModels, total, getAdminsErr := role_service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, page, 10)
64
+	if getAdminsErr != nil {
65
+		//beego.Error("获取管理员列表失败:", getAdminsErr)
66
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
67
+	} else {
68
+		this.ServeSuccessJSON(map[string]interface{}{
69
+			"admins":      viewModels,
70
+			"total_count": total,
71
+		})
72
+	}
73
+}
74
+
75
+// /api/admin/addinit [get]
76
+func (this *AdminAPIController) AddAdminInitData() {
77
+	adminUserInfo := this.GetAdminUserInfo()
78
+	if adminUserInfo.AdminUser.IsSuperAdmin == false {
79
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
80
+		return
81
+	}
82
+
83
+	roles, getRoleErr := role_service.GetAllValidRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
84
+	if getRoleErr != nil {
85
+		//beego.Error("获取所有角色失败:", getRoleErr)
86
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
87
+		return
88
+	}
89
+
90
+	redisClient := service.RedisClient()
91
+	defer redisClient.Close()
92
+	qntoken, _ := redisClient.Get("qn_token").Result()
93
+
94
+	this.ServeSuccessJSON(map[string]interface{}{
95
+		"roles":   roles,
96
+		"qntoken": qntoken,
97
+	})
98
+}
99
+
100
+// /api/admin/add [post]
101
+// @param mobile:string
102
+// @param name:string
103
+// @param type:int 管理员类型:2.医生 3.护士 4.运营
104
+// @param title:int 用户职称(1.医士;2.医师;3.住院医师;4.主治医师;5.副主任医师;6.主任医师;7.护士;8.护师;9.主管护师;10.副主任护师;11.主任护师;12.运营专员;13.运营主管)
105
+// @param role:int
106
+// @param intro?:string
107
+func (this *AdminAPIController) AddAdmin() {
108
+	adminUserInfo := this.GetAdminUserInfo()
109
+	if adminUserInfo.AdminUser.IsSuperAdmin == false {
110
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
111
+		return
112
+	}
113
+
114
+	mobile := this.GetString("mobile")
115
+	name := this.GetString("name")
116
+	userType, _ := this.GetInt("type")
117
+	userTitle, _ := this.GetInt("title")
118
+	roleId, _ := this.GetInt64("role")
119
+	intro := this.GetString("intro")
120
+
121
+	_, titleExist := models.UserTitle[userTitle]
122
+	if len(mobile) == 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || !titleExist || roleId <= 0 {
123
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
124
+		return
125
+	}
126
+
127
+	isRoleExist, getRoleErr := role_service.IsRoleExist(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, roleId)
128
+	if getRoleErr != nil {
129
+		//beego.Error("查询角色是否存在时失败:", getRoleErr)
130
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
131
+		return
132
+	}
133
+	if !isRoleExist {
134
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNotExist)
135
+		return
136
+	}
137
+
138
+	// 判断该应用是否已存在该手机号
139
+	if isMobileDidUsed, err := role_service.IsMobileDidUsedAtApp(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, mobile); err != nil {
140
+		//beego.Error("查询用户是否已被添加为管理员时失败:", err)
141
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
142
+		return
143
+	} else {
144
+		if isMobileDidUsed {
145
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMobileDidUsedInApp)
146
+			return
147
+		}
148
+	}
149
+
150
+	if isSuperAdmin, err := role_service.IsUserSuperAdminWithMobile(mobile); err != nil {
151
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMobileNotExit)
152
+		return
153
+	} else {
154
+		if isSuperAdmin {
155
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleMobileIsSuperAdmin)
156
+			return
157
+		}
158
+	}
159
+
160
+	_, password, createErr := role_service.CreateGeneralAdminUser(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, mobile, name, userType, userTitle, intro, roleId)
161
+	if createErr != nil {
162
+		//beego.Error("创建管理员失败:", createErr)
163
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
164
+		return
165
+
166
+	} else {
167
+		this.TraceLog("%v", password)
168
+		//beego.Trace("用户密码:", password)
169
+		// 发送短信通知这个手机号
170
+		// sendSMSErr := role_service.SMSSendInviteMobileToJoinOrgAdmin(name, mobile, password)
171
+		// if sendSMSErr != nil {
172
+		// 	//beego.Error("发送邀请短信失败:%v", sendSMSErr)
173
+		// }
174
+
175
+		this.ServeSuccessJSON(nil)
176
+		return
177
+	}
178
+}
179
+
180
+// /api/admin/editinit [get]
181
+// @param uid:int
182
+func (this *AdminAPIController) EditAdminInitData() {
183
+	adminUserInfo := this.GetAdminUserInfo()
184
+	if adminUserInfo.AdminUser.IsSuperAdmin == false {
185
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
186
+		return
187
+	}
188
+
189
+	admin_user_id, _ := this.GetInt64("uid")
190
+	if admin_user_id <= 0 {
191
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
192
+		return
193
+	}
194
+
195
+	adminUserViewModel, getInfoErr := role_service.GetGeneralAdminUser(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, admin_user_id)
196
+	if getInfoErr != nil {
197
+		//beego.Error("获取管理员信息失败:", getInfoErr)
198
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
199
+		return
200
+	}
201
+	if adminUserViewModel == nil {
202
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
203
+		return
204
+	}
205
+
206
+	roles, getRoleErr := role_service.GetAllValidRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
207
+	if getRoleErr != nil {
208
+		//beego.Error("获取所有角色失败:", getRoleErr)
209
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
210
+		return
211
+	}
212
+
213
+	redisClient := base_service.RedisClient()
214
+	defer redisClient.Close()
215
+	qntoken, _ := redisClient.Get("qn_token").Result()
216
+
217
+	this.ServeSuccessJSON(map[string]interface{}{
218
+		"admin":   adminUserViewModel,
219
+		"roles":   roles,
220
+		"qntoken": qntoken,
221
+	})
222
+}
223
+
224
+// /api/admin/edit [post]
225
+// @param uid:int
226
+// @param name:string
227
+// @param type:int
228
+// @param title:int
229
+// @param role:int
230
+// @param intro?:string
231
+func (this *AdminAPIController) EditAdmin() {
232
+	adminUserInfo := this.GetAdminUserInfo()
233
+	if adminUserInfo.AdminUser.IsSuperAdmin == false {
234
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
235
+		return
236
+	}
237
+
238
+	adminUserId, _ := this.GetInt64("uid")
239
+	name := this.GetString("name")
240
+	userType, _ := this.GetInt("type")
241
+	userTitle, _ := this.GetInt("title")
242
+	roleId, _ := this.GetInt64("role")
243
+	intro := this.GetString("intro")
244
+
245
+	_, titleExist := models.UserTitle[userTitle]
246
+	if adminUserId <= 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || !titleExist || roleId <= 0 {
247
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
248
+		return
249
+	}
250
+
251
+	appRole, getAppRoleErr := role_service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserId)
252
+	if getAppRoleErr != nil {
253
+		//beego.Error("查询管理员信息时失败:", getAppRoleErr)
254
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
255
+		return
256
+	}
257
+	if appRole == nil {
258
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
259
+		return
260
+	}
261
+
262
+	isRoleExist, getRoleErr := role_service.IsRoleExist(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, roleId)
263
+	if getRoleErr != nil {
264
+		//beego.Error("查询角色是否存在时失败:", getRoleErr)
265
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
266
+		return
267
+	}
268
+	if !isRoleExist {
269
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNotExist)
270
+		return
271
+	}
272
+
273
+	appRole.UserName = name
274
+	appRole.UserType = int8(userType)
275
+	appRole.UserTitle = int8(userTitle)
276
+	appRole.RoleId = roleId
277
+	appRole.Intro = intro
278
+	appRole.ModifyTime = time.Now().Unix()
279
+	saveErr := role_service.SaveAppRole(appRole)
280
+	if saveErr != nil {
281
+		//beego.Error("修改App_Role失败:", saveErr)
282
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
283
+
284
+	} else {
285
+		this.ServeSuccessJSON(nil)
286
+	}
287
+}
288
+
289
+// /api/admin/setstatus [post]
290
+// @param uid:int
291
+// @param enable:bool
292
+func (this *AdminAPIController) AdminSetStatus() {
293
+	adminUserInfo := this.GetAdminUserInfo()
294
+	if adminUserInfo.AdminUser.IsSuperAdmin == false {
295
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
296
+		return
297
+	}
298
+
299
+	userID, _ := this.GetInt64("uid")
300
+	if userID <= 0 {
301
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
302
+		return
303
+	}
304
+	appRole, getAppRoleErr := role_service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, userID)
305
+	if getAppRoleErr != nil {
306
+		//beego.Error("查询管理员信息失败:", getAppRoleErr)
307
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
308
+		return
309
+	} else if appRole == nil {
310
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
311
+		return
312
+	}
313
+
314
+	enable, _ := this.GetBool("enable")
315
+	if enable == true {
316
+		if roleEnable, _ := role_service.IsRoleExist(appRole.OrgId, appRole.AppId, appRole.RoleId); roleEnable == false {
317
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNotExist)
318
+			return
319
+		}
320
+	}
321
+
322
+	if enable {
323
+		appRole.Status = 1
324
+	} else {
325
+		appRole.Status = 0
326
+	}
327
+	appRole.ModifyTime = time.Now().Unix()
328
+	saveErr := role_service.SaveAppRole(appRole)
329
+	if saveErr != nil {
330
+		//beego.Error("保存AppRole失败:", saveErr)
331
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
332
+
333
+	} else {
334
+		this.ServeSuccessJSON(nil)
335
+	}
336
+}

+ 227 - 0
controllers/role/role_controller.go View File

1
+package role
2
+
3
+import (
4
+	base_ctl "SCRM/controllers"
5
+	"SCRM/enums"
6
+	"SCRM/service/role_service"
7
+	"time"
8
+
9
+	"github.com/astaxie/beego"
10
+)
11
+
12
+func RoleCtlRegistRouters() {
13
+	beego.Router("/api/roles", &RoleAPIController{}, "get:GetRoles")
14
+	beego.Router("/api/role/create", &RoleAPIController{}, "post:CreateRole")
15
+	beego.Router("/api/role/modify", &RoleAPIController{}, "post:ModifyRole")
16
+	beego.Router("/api/role/setstatus", &RoleAPIController{}, "post:ModifyRoleStatus")
17
+
18
+	beego.Router("/role/purview/editinit", &RoleAPIController{}, "get:EditPurviewInitData")
19
+	beego.Router("/role/purview/edit", &RoleAPIController{}, "post:EditPurview")
20
+}
21
+
22
+type RoleAPIController struct {
23
+	base_ctl.BaseAuthAPIController
24
+}
25
+
26
+// /api/roles [get]
27
+// @param page?:int
28
+func (this *RoleAPIController) GetRoles() {
29
+	page, _ := this.GetInt("page")
30
+	adminUserInfo := this.GetAdminUserInfo()
31
+	//beego.Alert(adminUserInfo.AdminUser)
32
+	if adminUserInfo.AdminUser.IsSuperAdmin == false {
33
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
34
+		return
35
+	}
36
+
37
+	if page <= 0 {
38
+		page = 1
39
+	}
40
+	roles, total, getRoleErr := role_service.GetRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, page, 10)
41
+	if getRoleErr != nil {
42
+		//beego.Error("获取角色列表失败:", getRoleErr)
43
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
44
+	} else {
45
+		this.ServeSuccessJSON(map[string]interface{}{
46
+			"roles":       roles,
47
+			"total_count": total,
48
+		})
49
+	}
50
+}
51
+
52
+// /api/role/create [post]
53
+// @param name:string
54
+// @param intro:string
55
+func (this *RoleAPIController) CreateRole() {
56
+	name := this.GetString("name")
57
+	intro := this.GetString("intro")
58
+	if len(name) == 0 || len(intro) == 0 {
59
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
60
+		return
61
+	}
62
+	adminUserInfo := this.GetAdminUserInfo()
63
+	if adminUserInfo.AdminUser.IsSuperAdmin == false {
64
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
65
+		return
66
+	}
67
+
68
+	role, createErr := role_service.CreateRole(adminUserInfo.AdminUser.Id, adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, name, intro)
69
+	if createErr != nil {
70
+		//beego.Error("创建角色失败:", createErr)
71
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
72
+	} else {
73
+		this.ServeSuccessJSON(map[string]interface{}{
74
+			"id":     role.Id,
75
+			"name":   role.RoleName,
76
+			"intro":  role.RoleIntro,
77
+			"status": role.Status,
78
+		})
79
+	}
80
+}
81
+
82
+// /api/role/modify
83
+// @param role_id:int
84
+// @param name:string
85
+// @param intro:string
86
+func (this *RoleAPIController) ModifyRole() {
87
+	roleID, _ := this.GetInt64("role_id")
88
+	name := this.GetString("name")
89
+	intro := this.GetString("intro")
90
+	if roleID <= 0 || len(name) == 0 || len(intro) == 0 {
91
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
92
+		return
93
+	}
94
+	adminUserInfo := this.GetAdminUserInfo()
95
+	if adminUserInfo.AdminUser.IsSuperAdmin == false {
96
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
97
+		return
98
+	}
99
+
100
+	role, getRoleErr := role_service.GetRoleByRoleID(roleID)
101
+	if getRoleErr != nil {
102
+		//beego.Error("获取角色失败:", getRoleErr)
103
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
104
+		return
105
+	} else if role == nil {
106
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNotExist)
107
+		return
108
+	}
109
+
110
+	role.RoleName = name
111
+	role.RoleIntro = intro
112
+	role.ModifyTime = time.Now().Unix()
113
+	saveErr := role_service.ModifyRole(role)
114
+	if saveErr != nil {
115
+		//beego.Error("修改角色失败:", role.Id, saveErr)
116
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
117
+	} else {
118
+		this.ServeSuccessJSON(nil)
119
+	}
120
+}
121
+
122
+// /api/role/setstatus
123
+// @param role_id:int
124
+// @param enable:bool
125
+func (this *RoleAPIController) ModifyRoleStatus() {
126
+	roleID, _ := this.GetInt64("role_id")
127
+	enable, _ := this.GetBool("enable")
128
+	if roleID <= 0 {
129
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
130
+		return
131
+	}
132
+
133
+	adminUserInfo := this.GetAdminUserInfo()
134
+	if adminUserInfo.AdminUser.IsSuperAdmin == false {
135
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
136
+		return
137
+	}
138
+
139
+	role, getRoleErr := role_service.GetRoleByRoleID(roleID)
140
+	if getRoleErr != nil {
141
+		//beego.Error("获取角色失败:", getRoleErr)
142
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
143
+		return
144
+	} else if role == nil {
145
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNotExist)
146
+		return
147
+	}
148
+
149
+	if enable == false {
150
+		if count, _ := role_service.RoleAdminUserCount(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, roleID); count != 0 {
151
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeCannotRemoveRole)
152
+			return
153
+		}
154
+	}
155
+
156
+	if enable {
157
+		role.Status = 1
158
+	} else {
159
+		role.Status = 2
160
+	}
161
+	role.ModifyTime = time.Now().Unix()
162
+	saveErr := role_service.ModifyRole(role)
163
+	if saveErr != nil {
164
+		//beego.Error("修改角色失败:", role.Id, saveErr)
165
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
166
+	} else {
167
+		this.ServeSuccessJSON(nil)
168
+	}
169
+}
170
+
171
+// /role/purview/editinit [get]
172
+// @param role_id:int
173
+func (this *RoleAPIController) EditPurviewInitData() {
174
+	adminUserInfo := this.GetAdminUserInfo()
175
+	if adminUserInfo.AdminUser.IsSuperAdmin == false {
176
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
177
+		return
178
+	}
179
+
180
+	roleId, _ := this.GetInt64("role_id")
181
+	if roleId <= 0 {
182
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
183
+		return
184
+	}
185
+	purviews, getPurviewsErr := role_service.GetAllGeneralPurviewVMsProcessed()
186
+	if getPurviewsErr != nil {
187
+		//beego.Error("获取所有权限时出错:", getPurviewsErr)
188
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
189
+		return
190
+	}
191
+	rolePurviewIdStr, getRPIdsErr := role_service.GetRolePurviewIds(roleId)
192
+	if getRPIdsErr != nil {
193
+		//beego.Error("获取角色的权限时出错:", getRPIdsErr)
194
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
195
+		return
196
+	}
197
+
198
+	this.ServeSuccessJSON(map[string]interface{}{
199
+		"purviews":         purviews,
200
+		"role_purview_ids": rolePurviewIdStr,
201
+	})
202
+}
203
+
204
+// /role/purview/edit [post]
205
+// @param role_id:int
206
+// @param purview_ids:string
207
+func (this *RoleAPIController) EditPurview() {
208
+	adminUserInfo := this.GetAdminUserInfo()
209
+	if adminUserInfo.AdminUser.IsSuperAdmin == false {
210
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
211
+		return
212
+	}
213
+	roleId, _ := this.GetInt64("role_id")
214
+	purviewIds := this.GetString("purview_ids")
215
+	if roleId <= 0 {
216
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
217
+		return
218
+	}
219
+
220
+	err := role_service.SaveRolePurviewIds(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, roleId, purviewIds)
221
+	if err != nil {
222
+		//beego.Error("设置角色的权限时出错:", err)
223
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
224
+	} else {
225
+		this.ServeSuccessJSON(nil)
226
+	}
227
+}

+ 6 - 0
controllers/role/router_collector.go View File

1
+package role
2
+
3
+func RegisterRouters() {
4
+	RoleCtlRegistRouters()
5
+	AdminCtlRegistRouters()
6
+}

+ 5 - 0
main.go View File

2
 
2
 
3
 import (
3
 import (
4
 	_ "SCRM/routers"
4
 	_ "SCRM/routers"
5
+	"SCRM/service"
5
 
6
 
6
 	"github.com/astaxie/beego"
7
 	"github.com/astaxie/beego"
7
 )
8
 )
8
 
9
 
10
+func init() {
11
+	service.ConnectDB()
12
+}
13
+
9
 func main() {
14
 func main() {
10
 	beego.Run()
15
 	beego.Run()
11
 }
16
 }

+ 4 - 2
routers/router.go View File

1
 package routers
1
 package routers
2
 
2
 
3
 import (
3
 import (
4
-	"SCRM/controllers/admin"
4
+	"SCRM/controllers/admin_user"
5
 	"SCRM/controllers/global"
5
 	"SCRM/controllers/global"
6
 	"SCRM/controllers/login"
6
 	"SCRM/controllers/login"
7
+	"SCRM/controllers/role"
7
 
8
 
8
 	"github.com/astaxie/beego"
9
 	"github.com/astaxie/beego"
9
 	"github.com/astaxie/beego/plugins/cors"
10
 	"github.com/astaxie/beego/plugins/cors"
19
 	}))
20
 	}))
20
 
21
 
21
 	global.RegisterRouters()
22
 	global.RegisterRouters()
22
-	admin.RegisterRouters()
23
+	admin_user.RegisterRouters()
23
 	login.RegisterRouters()
24
 	login.RegisterRouters()
25
+	role.RegisterRouters()
24
 }
26
 }