/*
获取养护考核流程节点用户权限
*/
@RequestMapping(value = "getAQZLRightes.html")
public void getAQZLRightes(HttpServletRequest request, HttpServletResponse response) {
String result = "[]";
String code = "-1";
String msg = "获取数据失败";
//获取app传递的参数
String id = request.getParameter("id");
String userID = request.getParameter("userID");
String yhkh_type = request.getParameter("type");
try {
//获取当前登录用户的权限,并且保存在session中
String rights = appService.getUserByName(userID).getRights();
request.getSession().setAttribute("userRights", rights);
//根据当前节点获取下一节点
List list = null;
list = appService.getAQZLRightes(request, id, userID, yhkh_type);
result = JSONArray.fromObject(list).toString();
msg = "获取数据成功";
code = "0";
} catch (Exception e) {
e.printStackTrace();
}
//组织返回结果
result = "{\"code\":\"" + code + "\",\"msg\":\"" + msg + "\",\"data\":" + result + "}";
// System.out.println("result:"+result);
//调用打印方法返回给前台
PrintWriterUtil.print(result, response);
}
/*
获取养护考核流程节点用户权限
*/
@Transactional(readOnly = true)
public List getAQZLRightes(HttpServletRequest request, String id, String username, String yhkh_type) {
//获取所有的下一级节点
List list = appDao.getAQZLRightes(id);
//获取相关案件信息
Map yhkh_map = appDao.getAQZLDetailes(id);
return getAQZLRightFlowStep(request, list, username, yhkh_type, yhkh_map);
}
权限比对
private List getAQZLRightFlowStep(HttpServletRequest request, List list, String userId, String yhkh_type, Map yhkh_map) {
List list_return = new ArrayList();
//循环判断是否有操作节点的权限
boolean flag = true;
boolean flag1 = true;
for (int i = 0; i < list.size(); i++) {
Map map = (HashMap) list.get(i);
if (!StringFacs.isEmpty(map) && !StringFacs.isEmpty(map.get("ID"))) {
List<RightinfoEntity> list_rights = rightinfoDao.getRightinfoByPid(map.get("ID").toString());
// System.out.println("list_rights:"+list_rights);
for (int j = 0; j < list_rights.size(); j++) {
RightinfoEntity rightinfoEntity = list_rights.get(j);
if (frontLoginDao.userHasRight(request.getSession(), rightinfoEntity.getPrightname(), rightinfoEntity.getRightname())) {
list_return.add(map);
break;
}
}
}
}
// System.out.println("list_return:"+list_return);
return list_return;
}
/**************************************************************
*函数功能: 获取用户在某个系统中是否有某个权限
*输入参数:
* session --获取该用户的所有权限
* groupName --需要获取用户在哪个组中的权限
* itemName --具体的权限名字,如果为空,表示计算用户在该系统下有无任一权限
**************************************************************/
public boolean userHasRight(HttpSession session, String groupName, String itemName){
if(session.getAttribute("userRights")==null) return false;
String userRights=(String)session.getAttribute("userRights");
//System.out.println("userRights="+userRights+"\ngroupName="+groupName+"\nitemName="+itemName);
if(userRights.indexOf("<"+groupName+">")>-1){
String innerRights=userRightInGroup(session,groupName);
if(StringFacs.isEmpty(itemName)){
//如果子权限的名字为空,则返回用户在这个系统下是否有权限,如果有任何一种权限,则返回true,反之,
//如果用户在该系统下一个权限都没有,则返回false
return innerRights.trim().length() > 0;
}
String[] la_rights=innerRights.split("~t");
//System.out.println("len:"+la_rights.length);
for (int i=0;i<la_rights.length;i++){
// System.out.println(i+":"+la_rights[i]+"\n");
if (la_rights[i].equalsIgnoreCase(itemName) || la_rights[i].equalsIgnoreCase("["+itemName+"]")){
//System.out.println("有该权限");
return true;
}
}
}else return false;
return false;
}