if(id==null)
{
result.setFailed(USER_ID_IS_NULL);
return result;
}
Users user = usersDAO.findById(id);
if(user==null)
{
result.setFailed(USER_NOT_EXIST);
return result;
}
if(user.getName().equalsIgnoreCase(DEFAULT_ROOT_USER))
{
result.setFailed(CANNOT_DELETE_ROOT_USER);
return result;
}
String sql1 = "delete from group_members where user_id=?";
String sql2 = "delete from authorities where user_id=?";
String sql3 = "delete from user_info where user_id=?";
try{
jdbcTemplate.update(sql1, id);
jdbcTemplate.update(sql2, id);
jdbcTemplate.update(sql3,id);
usersDAO.delete(user);
result.setSucceed();
}
catch(Exception e)
{
e.printStackTrace();
result.setFailed(e.getMessage());
return result;
}
/**
* 日志记录删除操作,操作者;
* */
UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext()
.getAuthentication().getPrincipal();
String currentUserName = userDetails.getUsername();
String info = new StringBuffer().append("User ").append(user.getName()).append(" is delete by")
.append(currentUserName).toString();
LOG.info(info);
return result;
}