Ejemplo n.º 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);
  }
Ejemplo n.º 2
0
 @POST
 @Path("/add")
 @Auth(resourceCode = "10010")
 @DescriptionAuth(description = "新增用户", module = "用户管理")
 public ExtJSResponse add(User user) {
   if (user == null) {
     logger.error("新增用户出错,用户信息为空!");
     return ExtJSResponse.errorRes("新增用户出错,用户信息为空!");
   }
   //        通过login_name查出已注册的用户,确保login_name的唯一性
   UserExample example = new UserExample();
   example.createCriteria().andLoginNameEqualTo(user.getLoginName()).andStatusGreaterThan(0);
   List<User> list = userMapper.selectByExample(example);
   if (list != null && !list.isEmpty()) {
     return ExtJSResponse.errorRes("用户名已存在,请重新输入!");
   }
   Integer currentUserId = SysContent.getUser().getId();
   user.setCreator(currentUserId);
   user.setModifier(currentUserId);
   //        user.setPassword(MD5.md5(user.getPassword()));
   user.setStatus(Status.NORMAL.getCode());
   userMapper.insert(user);
   List<Integer> roleList = user.getRoleList();
   if (roleList == null || roleList.isEmpty()) {
     return ExtJSResponse.successRes();
   }
   List<UserRole> 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();
 }
Ejemplo n.º 3
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();
 }