发表于: 2018-01-14 18:51:16

1 757


今日完成:

看了书,写了个权限判断。


明日计划:

看看能不能优化一下权限判断性能。


成果:

权限判断工具类,在登陆的时候我会把这个用户的权限表存入session,然后powerList从session取出放入,第二个是模块名,第三个是权限类型(增删改查),功能是能实现的,就是有点慢,处理时间260ms左右,直接超了90 line,很迷茫。

public static boolean powerJudge(List<Rolewithmodule> powerList,String moduleName,String powerType) throws ServiceException, ServiceDaoException, IllegalAccessException {
Long start=new Date().getTime();
   List<Module> moduleList=moduleService.getObjectsByIds(moduleService.getModuleIds(0,Integer.MAX_VALUE));
  for (Module module:moduleList){
if (module.getModuleName().contains(moduleName)) {
for (Rolewithmodule power:powerList){
if (power.getModuleId().equals(module.getId())){
Field[] fields=Rolewithmodule.class.getDeclaredFields();
                   for (Field field:fields){
field.setAccessible(true);
                       if(field.getName().equals(powerType+"Power")){
if ((Long)field.get(power)==1l){
System.out.println(new Date().getTime()-start+"ssssssssssssssssssssssssssssssssssss");
                               return true;
                           }
}
}
}
}
}
}
System.out.println(new Date().getTime()-start+"ssssssssssssssssssssssssssssssssssss");
   return false;
}

调用:

其中session取的值必须判空先,不然在没有数据的情况下会出现空指针异常。

//session获取此用户权限
List<Rolewithmodule> powerList=(List<Rolewithmodule>) request.getSession().getAttribute("power");
if (DataUtils.isNullOrEmpty(powerList)){
log.info("this user don't have power to add company");
  model.addAttribute("code",-7005);
  return "pagescarrots-youneedboy-home-service/data/json";
}
//权限判断
if (!PowerJudgement.powerJudge(powerList,"公司","add")){
log.info("this user don't have power to insert company");
  model.addAttribute("code",-7005);
  return "pagescarrots-youneedboy-home-service/data/json";
}


明日计划:

优化性能

禅道:

http://task.ptteng.com/zentao/my-task.html





返回列表 返回列表
评论

    分享到