/**
   * @Title: getMenu @Description: TODO @Autohr guoxuelian#symdata.cn
   *
   * @param @param username
   * @param @param systemId
   * @param @return
   * @param @throws DatabaseException
   * @return TransDto
   * @throws 2015年9月14日下午3:48:49
   */
  @RequestMapping(value = "/menu", method = RequestMethod.POST)
  public TransDto getMenu(String username, String systemId) throws DatabaseException {
    TransDto dto = new TransDto();

    if (!StringUtils.isNotBlank(username) || !StringUtils.isNotBlank(systemId)) {
      dto.setError(ErrorCode.ERR1001.getCode(), ErrorCode.ERR1001.getDescription(), null);
      return dto;
    }
    User user = userService.findByUsername(username);
    if (user == null) {
      dto.setError(ErrorCode.ERR1002.getCode(), ErrorCode.ERR1002.getDescription(), null);
      return dto;
    }
    List<MenuDto> menuListDto = remoteInterface.getMenu(user, systemId);
    dto.setDefaultSuccess(menuListDto);
    return dto;
  }
  /**
   * @param username
   * @param password
   * @return @Description:用户查询 @Author:zhangnan#symdata @Since:2015年9月6日 下午8:11:16 @Version:1.0
   */
  @RequestMapping(value = "/queryUser", method = RequestMethod.POST)
  public TransDto login(String username) throws DatabaseException {
    TransDto dto = new TransDto();
    UserDto userDto = null;

    if (!StringUtils.isNotBlank(username)) {
      dto.setError(ErrorCode.ERR1001.getCode(), ErrorCode.ERR1001.getDescription(), null);
      return dto;
    }
    User user = userService.findByUsername(username);
    if (user == null) {
      dto.setError(ErrorCode.ERR1002.getCode(), ErrorCode.ERR1002.getDescription(), null);
      return dto;
    }
    userDto = remoteInterface.remoteLogin(user, username);
    dto.setDefaultSuccess(userDto);
    return dto;
  }
 @SuppressWarnings({"rawtypes"})
 public void execute(
     Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
     throws TemplateException, IOException {
   List<Menu> menus = Lists.newArrayList();
   String username = null;
   Subject subject = SecurityUtils.getSubject();
   if (subject != null) {
     Principal principal = (Principal) subject.getPrincipal();
     if (principal != null) {
       username = principal.getUsername();
     }
   }
   try {
     if (username != null) {
       User user = userService.findByUsername(username);
       menus = user.getMenuList(config.getSystemId());
     }
   } catch (DatabaseException e) {
     e.printStackTrace();
   }
   setLocalVariable(VARIABLE_NAME, menus, env, body);
 }
  /**
   * @Title: modifyPassword @Description: 修改密码 @Autohr guoxuelian#symdata.cn
   *
   * @param @param username
   * @param @param newPwd
   * @param @param oldPwd
   * @param @return
   * @param @throws DatabaseException
   * @return TransDto
   * @throws 2015年9月16日下午5:03:52
   */
  @RequestMapping(value = "/modifyPassword", method = RequestMethod.POST)
  public TransDto modifyPassword(String username, String newPwd, String oldPwd)
      throws DatabaseException {
    TransDto dto = new TransDto();

    if (!StringUtils.isNotBlank(username)
        || !StringUtils.isNotBlank(newPwd)
        || !StringUtils.isNotBlank(oldPwd)) { // 参数错误
      dto.setError(ErrorCode.ERR1001.getCode(), ErrorCode.ERR1001.getDescription(), null);
      return dto;
    }
    User user = userService.findByUsername(username);
    if (user == null) { // 找不到该用户
      dto.setError(ErrorCode.ERR1002.getCode(), ErrorCode.ERR1002.getDescription(), null);
      return dto;
    }
    if (!oldPwd.equals(user.getPassword())) { // 老密码错误
      dto.setError(ErrorCode.ERR1003.getCode(), ErrorCode.ERR1003.getDescription(), null);
      return dto;
    }
    remoteInterface.updatePassword(username, newPwd);
    dto.setDefaultSuccess(null);
    return dto;
  }