예제 #1
0
  @GET
  @Path("/roleTree")
  public ExtJSResponse loadTree(final @QueryParam("userId") int userId) {
    // 先获取所有的权限信息
    RoleExample roleExample = new RoleExample();
    roleExample.createCriteria().andStatusEqualTo(Status.NORMAL.getCode());
    List<Role> roleList = roleMapper.selectByExample(roleExample);
    List<TreeNode> treeNodeList = new ArrayList<TreeNode>();
    for (Role role : roleList) {
      TreeNode roleTree = new TreeNode();
      roleTree.setId(role.getRoleId());
      roleTree.setText(role.getRoleName());
      roleTree.setLeaf(true);
      roleTree.setChecked(false);
      roleTree.setChildren(null);
      treeNodeList.add(roleTree);
    }
    // 如果userId!=0  表示此时的操作是edit 将用户原有权限的checked置为true
    if (userId != 0) {
      UserRoleExample userRoleExample = new UserRoleExample();
      userRoleExample.createCriteria().andUserIdEqualTo(userId);
      List<UserRole> userRoleList = userRoleMapper.selectByExample(userRoleExample);
      for (UserRole userRole : userRoleList) {
        for (TreeNode roleTree : treeNodeList) {
          if (userRole.getRoleId().compareTo(roleTree.getId()) == 0) {
            roleTree.setChecked(true);
          }
        }
      }
      return ExtJSResponse.successResWithData(treeNodeList);
    }

    return ExtJSResponse.successResWithData(treeNodeList);
  }
예제 #2
0
 @POST
 @Path("/edit")
 @Auth(resourceCode = "10012")
 @DescriptionAuth(description = "修改用户", module = "用户管理")
 public ExtJSResponse edit(User user) {
   System.out.println("修改用户");
   if (user == null || user.getId() == null) {
     logger.error("修改用户出错,用户信息为空!");
     return ExtJSResponse.errorRes("新增用户出错,用户信息为空!");
   }
   Integer currentUserId = SysContent.getUser().getId();
   user.setModifier(currentUserId);
   user.setPassword(MD5.md5(user.getPassword()));
   userMapper.updateByPrimaryKeySelective(user);
   UserRoleExample userRoleExample = new UserRoleExample();
   userRoleExample.createCriteria().andUserIdEqualTo(user.getId());
   List<UserRole> userRoleList = userRoleMapper.selectByExample(userRoleExample);
   // 批量插入
   if (userRoleList.size() > 0) {
     userRoleHisMapper.insertBatch(userRoleList);
   }
   userRoleMapper.deleteByExample(userRoleExample);
   List<Integer> roleList = user.getRoleList();
   if (roleList == null || roleList.isEmpty()) {
     return ExtJSResponse.successRes();
   }
   userRoleList = new ArrayList<UserRole>(roleList.size());
   for (Integer roleId : roleList) {
     UserRole userRole = new UserRole();
     userRole.setUserId(user.getId());
     userRole.setRoleId(roleId);
     userRole.setCreator(currentUserId);
     userRoleList.add(userRole);
   }
   userRoleMapper.insertBatch(userRoleList);
   return ExtJSResponse.successRes();
 }