Пример #1
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();
 }
Пример #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();
 }