ERP系统常见的问题:操作权限、数据权限的解决方案
1、页面:通过权限控制某个页面是否显示
2、按钮:通过权限控制某个页面上的按钮是否显示
3、方法:通过权限控制某个方法是否能够访问
4、数据行:通过权限控制某个用户只能看到几行数据
后台设置权限
1、操作权限:添加计划、修改计划、搜索计划权限
2、数据权限:本人、本部门、所有
实现设置
1、页面:通过请求查询用户有哪些权限-有哪些模块
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
function
loadMenu(){
$.ajax({
url :
""
,
type :
"post"
,
dataType :
"jsonp"
,
jsonp:
"jsonpCallback"
,
success :
function
(result) {
var
lefthtml=
"<li><a href=''><i class='fa fa-tachometer fa-fw'></i> <span class='menu-text'>首页</span></a> </li>"
;
var
category=
""
;
var
i=0;
$(result.leftModule).each(
function
(){
if
(
this
.categoryName!=category){
if
(i!=0){
lefthtml=lefthtml+
"</ul></li>"
;
}
lefthtml=lefthtml+
"<li class='has-sub'>"
;
lefthtml=lefthtml+
"<a href='javascript:;' class=''>"
;
if
(
this
.categoryName==
"客源管理"
){
lefthtml=lefthtml+
"<i class='fa fa-user fa-fw'></i> <span class='menu-text'>"
+
this
.categoryName+
"</span>"
;
}
else
if
(
this
.categoryName==
"房源管理"
){
lefthtml=lefthtml+
"<i class='fa fa-home fa-fw'></i> <span class='menu-text'>"
+
this
.categoryName+
"</span>"
;
}
else
if
(
this
.categoryName==
"我的首页"
){
lefthtml=lefthtml+
"<i class='fa fa-bookmark-o fa-fw'></i> <span class='menu-text'>"
+
this
.categoryName+
"</span>"
;
}
else
if
(
this
.categoryName==
"签约管理"
){
lefthtml=lefthtml+
"<i class='fa fa-edit fa-fw'></i> <span class='menu-text'>"
+
this
.categoryName+
"</span>"
;
}
else
if
(
this
.categoryName==
"文档公告管理"
){
lefthtml=lefthtml+
"<i class='fa fa-folder-open fa-fw'></i> <span class='menu-text'>"
+
this
.categoryName+
"</span>"
;
}
else
if
(
this
.categoryName==
"跟进管理"
){
lefthtml=lefthtml+
"<i class='fa fa-hand-o-right fa-fw'></i> <span class='menu-text'>"
+
this
.categoryName+
"</span>"
;
}
else
{
lefthtml=lefthtml+
"<i class='fa fa-bookmark-o fa-fw'></i> <span class='menu-text'>"
+
this
.categoryName+
"</span>"
;
}
lefthtml=lefthtml+
"<span class='arrow'></span>"
;
lefthtml=lefthtml+
"</a>"
;
lefthtml=lefthtml+
"<ul class='sub'>"
;
lefthtml=lefthtml+
"<li><a class='' href='"
+
this
.link+
"'><span class='sub-menu-text'>"
+
this
.moduleName+
"</span></a></li>"
;
category=
this
.categoryName;
}
else
{
lefthtml=lefthtml+
"<li><a class='' href='"
+
this
.link+
"'><span class='sub-menu-text'>"
+
this
.moduleName+
"</span></a></li>"
;
}
if
(i==result.leftModule.length-1){
lefthtml=lefthtml+
"</ul></li>"
;
}
i++;
});
$(
"#leftMenu"
).html(lefthtml);
},
error :
function
(err) {
}
});
|
2、按钮 跟进登录人查询该用户有哪些权限码,在每个按钮的设置auth-code="shs_pair"属性
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
function
valideAction(){
$.ajax({
url :
""
,
type:
"post"
,
data: {actionCookies:$.cookie(
'actionCookie'
)},
dataType:
"jsonp"
,
jsonp:
"jsonpCallback"
,
success :
function
(result){
var
authCodeArray=
new
Array();
$(result).each(
function
(){
authCodeArray.push(
this
.actionCode);
});
$(
"[auth-code]"
).each(
function
(){
var
auth_code=$(
this
).attr(
"auth-code"
);
if
($.inArray(auth_code, authCodeArray)==-1){
$(
this
).remove();
}
});
}
});
}
|
3、方法 通过权限拦截器
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
public
String intercept(ActionInvocation invocation)
throws
Exception {
ActionContext actionContext = invocation.getInvocationContext();
HttpServletRequest request = (HttpServletRequest) actionContext
.get(StrutsStatics.HTTP_REQUEST);
HttpServletResponse response = (HttpServletResponse) actionContext
.get(StrutsStatics.HTTP_RESPONSE);
ActionProxy actionProxy = invocation.getProxy();
String methodName = actionProxy.getMethod();
if
(StringUtils.isBlank(methodName)) {
methodName =
"execute"
;
}
Class aClass = actionProxy.getAction().getClass();
Method method = aClass.getMethod(methodName);
PermissionsCode annotation = method
.getAnnotation(PermissionsCode.
class
);
String pin = (String) ActionContext.getContext().get(SystemDict.ERP_PIN);
/* String actionCookie= cookieUtil.getCookieValue(cookieKeyName);
String actionJson= SecurityUtil.decrypt(actionCookie,cookieEncrypt.get("desPrefix"));*/
LOG.info("登录人pin----------------"+pin);
if (pin!=null&&!pin.equals(adminPin)) {
/*List<Map<String,Object>> listPermissions=null;
if(actionJson!=null){
listPermissions= JsonUtil.fromJson(actionJson,List.class,Map.class);
}*/
List<ActionResult> actionlist=actionRpc.getActionList(pin);
if
(annotation !=
null
&& StringUtils.isNotBlank(annotation.code())) {
String code = annotation.code();
if
(actionlist!=
null
&& actionlist.size()!=
0
){
for
(ActionResult action : actionlist){
if
(code.equals(action.getActionCode())){
//如果正确则继续执行
this
.setScopeContext(action.getScope());
return
invocation.invoke();
}
}
}
}
else
{
//如果没有权限码则跳过
return
invocation.invoke();
}
}
else
{
//如果是admin跳过权限码
return
invocation.invoke();
}
//跳转错误页面
this
.redirect(request, response);
return
null
;
}
|
4、数据行:首先用户有这个权限,同时获取出该权限的权限范围(本人、本部门、所有)
根据用户的权限范围查询数据行
本文转自 xinsir999 51CTO博客,原文链接:http://blog.51cto.com/xinsir/1869480,如需转载请自行联系原作者