发表于: 2017-12-29 18:54:24

1 482


今日完成:

接口逻辑维护,删除模块角色时权限关联表同时维护,重写登陆和根据角色返回权限的接口。


明日计划:

我们的项目结构似乎要重构。。。。。我的模块基本写完,但是伙伴又说不需要帮忙。。很惆怅。


遇到的困难:

没遇到什么困难,主要就是麻烦,步骤繁琐,应该还有很多地方没有注意到。


成果:

登陆时返回用户信息和模块权限,符合了前端的要求。

因为本身taglib是基于对象在jsp上生成json的,但是我的user对象没有和模块相关的东西,然后就想到用hashmap来传数据,试了一下成功了,但是逻辑很绕,先是判断账号的正确性,如果可以获取到id证明验证成功,然后根据用户的角色id在权限关联表取出这个这个角色id上的模块id,然后用这些模块id通过遍历获取其父模块id,然后再把父模块id和子模块id整合然后取出所有模块放入hashmap,之后返回给前端,他们说这样方便点。

Long userId=userService.getUserIdByPhoneAndPassword(phone,password);

if(userId!=null) {

User user = userService.getObjectById(userId);

  List<Rolewithmodule> powerList = rolewithmoduleService.getObjectsByIds(rolewithmoduleService.getRolewithmoduleIdsByRoleId(user.getRoleId(), 0, Integer.MAX_VALUE));
  List idList = new ArrayList();
  List<Long> parentId = new ArrayList<Long>();
  for (Rolewithmodule rr : powerList) {
idList.add(rr.getModuleId());
  }

List<Module> moduleList = moduleService.getObjectsByIds(idList);

  for (Module module : moduleList) {
System.out.println(parentId.contains(module.getParentId()));
     if (!parentId.contains(module.getParentId())) {
parentId.add(module.getParentId());
     }
}

for (Long pid : parentId) {
moduleList.add(moduleService.getObjectById(pid));
  }
List mapList = new ArrayList<HashMap>();
  for (Module mm : moduleList) {
Map map = new HashMap();
     map.put("id", mm.getId());
     map.put("moduleName", mm.getModuleName());
     map.put("moduleType", mm.getModuleType());
     map.put("parentId", mm.getParentId());
     map.put("moduleType", mm.getModuleType());
     map.put("url", mm.getUrl());
     for (Rolewithmodule rr : powerList) {

if (rr.getModuleId().equals(mm.getId())) {
map.put("addPower", rr.getAddPower());
           map.put("deletePower", rr.getDeletePower());
           map.put("updatePower", rr.getUpdatePower());
        }
}
mapList.add(map);
  }


model.addAttribute("code", 0);
  model.addAttribute("total", powerList.size());
  model.addAttribute("user", user);
  model.addAttribute("mapList", mapList);

返回的的数据:

{"code":0,"message":"success message","data":{"id":1,"userName":"施星大佬","password":"shixing","phone":123456,"roleId":1,"roleName":"超级管理员","createBy":0,"updateBy":0,"updateAt":1514436194744,"createAt":1513993740000,"roleOfUser":[{"id":4,"moduleName":"公司列表","parentId":1,"moduleType":"","url":"companyList","addPower":1,"deletePower":1,"updatePower":1},{"id":5,"moduleName":"职位列表","parentId":1,"moduleType":"","url":"positionList","addPower":1,"deletePower":1,"updatePower":1},{"id":6,"moduleName":"article管理","parentId":2,"moduleType":"","url":"articleList","addPower":1,"deletePower":1,"updatePower":1},{"id":7,"moduleName":"账号管理","parentId":3,"moduleType":"","url":"accountManagement","addPower":1,"deletePower":1,"updatePower":1},{"id":8,"moduleName":"角色管理","parentId":3,"moduleType":"","url":"roleManagement","addPower":1,"deletePower":1,"updatePower":1},{"id":9,"moduleName":"模块管理","parentId":3,"moduleType":"","url":"moduleManagement","addPower":1,"deletePower":1,"updatePower":1},{"id":10,"moduleName":"之上管理","parentId":1,"moduleType":"","url":"","addPower":1,"deletePower":1,"updatePower":1},{"id":1,"moduleName":"信息管理","parentId":0,"moduleType":"","url":"","addPower":"","deletePower":"","updatePower":""},{"id":2,"moduleName":"内容管理","parentId":0,"moduleType":"","url":"","addPower":"","deletePower":"","updatePower":""},{"id":3,"moduleName":"后台管理","parentId":0,"moduleType":"","url":"","addPower":"","deletePower":"","updatePower":""}]}}


进度:

基本写完接口,思考项目优化。


禅道:

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






返回列表 返回列表
评论

    分享到