/*
   *
   * (non-Javadoc)
   *
   * @see com.opensymphony.xwork.ActionSupport#execute()
   */
  public String execute() {
    Module moduleVO = new Module();
    Module oldModuleVO = null;
    try {

      /** 验证请求的属性是否完整,防止知道URL非法请求----开始 */
      String name = this.getRequest().getParameter("name");
      String parentId = this.getRequest().getParameter("parentId");
      String actionUrl = this.getRequest().getParameter("actionUrl");
      String moduleLevel = this.getRequest().getParameter("moduleLevel");
      String viewType = this.getRequest().getParameter("viewType");
      String moduleSort = this.getRequest().getParameter("moduleSort");
      if (StringUtils.hasText(name)
          && StringUtils.hasText(parentId)
          && StringUtils.hasText(actionUrl)
          && StringUtils.hasText(moduleLevel)
          && StringUtils.hasText(viewType)
          && StringUtils.hasText(moduleSort)) {
        try {
          NumberUtils.parseNumber(parentId, Integer.class);
          NumberUtils.parseNumber(moduleLevel, Integer.class);
          NumberUtils.parseNumber(moduleSort, Integer.class);
        } catch (Exception e) {
          /** 记录日志 */
          LogsApplication appLog = new LogsApplication();
          appLog.setOperator(this.getUserSessionInfo().getName());
          appLog.setLogDate(new Date());
          appLog.setEventType("新增一级模块异常");
          appLog.setContent(
              "操作员["
                  + this.getUserSessionInfo().getName()
                  + "]"
                  + "新增一级模块出现异常,异常信息:["
                  + e.getMessage()
                  + "]!");
          appLog.setPriority(LogsApplication.EXCEPTION);
          appLog.setIpAddress(this.getUserSessionInfo().getIpAddress());
          this.appLogManager.saveOrUpdateAppLog(appLog);

          /** 输出错误信息 */
          logger.error(e.getMessage());
          e.printStackTrace();

          return INPUT;
        }
        /** 每个属性都有内容表示正常 */
      } else {
        /** 记录日志 */
        LogsApplication appLog = new LogsApplication();
        appLog.setOperator(this.getUserSessionInfo().getName());
        appLog.setLogDate(new Date());
        appLog.setEventType("新增一级模块异常");
        appLog.setContent(
            "操作员["
                + this.getUserSessionInfo().getName()
                + "]"
                + "新增一级模块出现异常,异常信息:["
                + "必填属性值有空值"
                + "]!");
        appLog.setPriority(LogsApplication.EXCEPTION);
        appLog.setIpAddress(this.getUserSessionInfo().getIpAddress());
        this.appLogManager.saveOrUpdateAppLog(appLog);

        logger.error("必填属性值有空值");

        /** 有空值的属性,返回 */
        return INPUT;
      }

      /** 验证请求的属性是否完整----结束 */

      /** 验证模块是否存在 */
      oldModuleVO = this.getModuleManager().getModuleByModuleName(StringUtils.trimWhitespace(name));
      if (oldModuleVO != null) {
        this.getRequest()
            .setAttribute(
                "actionName",
                this.getWebApplitionUrl() + "/webmanager/module/toAddFirstModule.action");
        return "existModule";
      }

      /** 添加模块 */
      // BeanUtils.copyProperties(moduleVO, moduleFormBean);
      // BeanUtil会将null的属性赋值为0||""。
      moduleVO.setId(null);
      moduleVO.setName(StringUtils.trimWhitespace(name));
      moduleVO.setParentId(
          (Integer) NumberUtils.parseNumber(StringUtils.trimWhitespace(parentId), Integer.class));
      moduleVO.setActionUrl(StringUtils.trimWhitespace(actionUrl));
      moduleVO.setModuleLevel(
          (Integer)
              NumberUtils.parseNumber(StringUtils.trimWhitespace(moduleLevel), Integer.class));
      moduleVO.setViewType(StringUtils.trimWhitespace(viewType));
      moduleVO.setModuleSort(
          (Integer) NumberUtils.parseNumber(StringUtils.trimWhitespace(moduleSort), Integer.class));

      /** 添加 */
      this.getModuleManager().saveOrUpdateModule(moduleVO);

      /** 记录日志 */
      LogsApplication appLog = new LogsApplication();
      appLog.setOperator(this.getUserSessionInfo().getName());
      appLog.setLogDate(new Date());
      appLog.setEventType("新增一级模块");
      appLog.setContent(
          "操作员["
              + this.getUserSessionInfo().getName()
              + "]"
              + "新增一级模块,新增一级模块是["
              + moduleVO.getName()
              + "]!");
      appLog.setPriority(LogsApplication.NORMAL);
      appLog.setIpAddress(this.getUserSessionInfo().getIpAddress());
      this.appLogManager.saveOrUpdateAppLog(appLog);

      return SUCCESS;

    } catch (Exception e) {
      /** 记录日志 */
      LogsApplication appLog = new LogsApplication();
      appLog.setOperator(this.getUserSessionInfo().getName());
      appLog.setLogDate(new Date());
      appLog.setEventType("新增一级模块异常");
      appLog.setContent(
          "操作员["
              + this.getUserSessionInfo().getName()
              + "]"
              + "新增一级模块出现异常,异常信息:["
              + e.getMessage()
              + "]!");
      appLog.setPriority(LogsApplication.EXCEPTION);
      appLog.setIpAddress(this.getUserSessionInfo().getIpAddress());
      this.appLogManager.saveOrUpdateAppLog(appLog);

      /** 输出错误信息 */
      logger.error(e.getMessage());
      e.printStackTrace();

      return ERROR;
    }
  }