public SqlConfig getSqlConfig(QueryValueFetchByJdbcSql agentClass, HttpServletRequest request) {
    // 将配置的Sql元素传送给SqlConfig
    SqlConfig sqlConfig = new SqlConfig();
    //    SqlString sqlStringSelect = new SqlString(agentClass.sqlSelect);
    //    sqlConfig.sqlSelect = sqlStringSelect.getParseSql(request, null);
    // sqlConfig.sqlStringSelect = this.sqlStringSelect;
    //    sqlConfig.sqlStringFromWhere = agentClass.sqlStringFromWhere;

    //      sqlConfig.sqlFromWhere = sqlConfig.sqlStringFromWhere.getParseSql(request,
    // this.replaceMap);
    //    sqlConfig.sqlSelect = sqlConfig.sqlStringSelect.getParseSql(request, this.replaceMap);

    sqlConfig.sqlData =
        "select "
            + agentClass.sqlSelect
            + " "
            + agentClass.sqlStringFromWhere.getParseSql(request, agentClass.replaceMap);
    //        sqlConfig.sqlSum = agentClass.sqlSum;
    //        if(sqlConfig.sqlSum.length() > 0)
    //          sqlConfig.sqlDataSum = "select " + sqlConfig.sqlSum + " " + sqlConfig.sqlFromWhere;
    //        sqlConfig.sqlCount = "select count(*) from (" + sqlConfig.sqlData + ")"; // +
    // sqlConfig.sqlFromWhere;
    //        String query_sortcol = RequestUtils.getStringParameter(request, "query_sortcol", "");
    sqlConfig.sqlOrder = agentClass.sqlOrder;
    //        if(!StringUtils.isBlank(query_sortcol))
    //        {
    //          sqlConfig.sqlOrder = " order by " + query_sortcol + " " +
    // RequestUtils.getStringParameter(request, "query_sortdir", "");
    //        }
    //        sqlConfig.sqlOrder = StringUtils.trimToEmpty(sqlConfig.sqlOrder);
    sqlConfig.isOverrideCache = true;
    return sqlConfig;
  }
  /**
   * 运行查询
   *
   * @param request HttpServletRequest
   * @return QueryValue
   */
  public QueryValue run(HttpServletRequest request) {
    CalTime calTime = new CalTime();
    CalTime calTimeSub = new CalTime();
    // 获取结果
    QueryValue queryValue = new QueryValue();
    request.setAttribute("queryValue", queryValue);

    // 获取运行次数
    queryValue.queryName = this.getQuery().getQueryName();
    queryValue.lastQueryName = RequestUtils.getStringParameter(request, "QueryName", "");
    if (queryValue.queryName.equals(queryValue.lastQueryName)) queryValue.runTime = 1;
    else {
      if (queryValue.lastQueryName.equals("")) queryValue.runTime = 0;
      else queryValue.runTime = -1;
    }

    // 解析参数中的页面大小和页数

    queryValue.pageSize = RequestUtils.getIntParameter(request, "query_pagesize", 0);
    if (queryValue.pageSize == 0) queryValue.pageSize = this.pageSize;
    queryValue.pageNo =
        RequestUtils.getIntParameter(request, queryValue.queryName + "_query_pageno", 1);

    // 将配置的Sql元素传送给SqlConfig
    SqlConfig sqlConfig = new SqlConfig();
    SqlString sqlStringSelect = new SqlString(this.sqlSelect);
    sqlConfig.sqlSelect = sqlStringSelect.getParseSql(request, null);
    // sqlConfig.sqlStringSelect = this.sqlStringSelect;
    sqlConfig.sqlStringFromWhere = this.sqlStringFromWhere;

    // 统计解析
    String sqlGroup = "";
    String sqlGroupSelectGroup = "";
    queryValue.drillURL = drillURL;
    queryValue.needTotalX = this.needTotalX;
    queryValue.needTotalY = this.needTotalY;

    if (groupList != null) {
      // 统计没有分页
      queryValue.pageSize = -1;
      StringBuffer sqlGroupSb = new StringBuffer();
      StringBuffer sqlGroupSelectGroupSb = new StringBuffer();
      queryValue.groupRalationList = this.groupRelationList;
      queryValue.groupList = new ArrayList();

      // 初始化XYZ轴

      if (queryValue.runTime != 1) // 第一次运行和从别的查询过来
      {
        queryValue.groupListY = (ArrayList) this.groupListY.clone();
        queryValue.groupListX = (ArrayList) this.groupListX.clone();
        queryValue.groupListSelect = (ArrayList) this.groupListSelect.clone();
        queryValue.groupList = (ArrayList) this.groupList.clone();
      } // end 初始化XYZ轴 if
      else {
        // 从Request中获取用户选择的X、Y轴

        queryValue.groupListY = new ArrayList();
        queryValue.groupListX = new ArrayList();
        queryValue.groupListSelect = new ArrayList();

        // Y轴

        String[] groupYName = RequestUtils.getStringParameters(request, "groupYName");
        String[] checkGroupYSubTotal =
            RequestUtils.getStringParameters(request, "checkGroupYSubTotal");
        for (int i = 0; i < groupYName.length; i++) {
          Object obj = groupMap.get(groupYName[i]);
          if (obj != null) {
            Group group = (Group) ((Group) obj).clone();
            group.position = 'y' + String.valueOf(i + 1);
            if (ArrayUtils.contains(checkGroupYSubTotal, groupYName[i])) group.needSubTotal = true;
            else group.needSubTotal = false;
            queryValue.groupListY.add(group);
          }
        }

        // X轴

        String[] groupXName = RequestUtils.getStringParameters(request, "groupXName");
        for (int i = 0; i < groupXName.length; i++) {
          Object obj = groupMap.get(groupXName[i]);
          if (obj != null) {
            Group group = (Group) ((Group) obj).clone();
            group.position = 'x' + String.valueOf(i + 1);
            queryValue.groupListX.add(group);
          }
        }

        // Z轴

        String[] groupList = RequestUtils.getStringParameters(request, "groupZName");
        for (int i = 0; i < groupList.length; i++) {
          Object obj = groupMap.get(groupList[i]);
          if (obj != null) {
            Group group = (Group) ((Group) obj).clone();
            group.position = String.valueOf(i + 1);
            queryValue.groupListSelect.add(group);
          }
        }
        queryValue.groupList.addAll(queryValue.groupListX);
        queryValue.groupList.addAll(queryValue.groupListY);
      } // end 初始化XYZ轴 else

      if (!(queryValue.runTime == 0 && !firstShow)) {
        for (int i = 0; i < queryValue.groupList.size(); i++) {
          Group group = (Group) queryValue.groupList.get(i);
          if (group.metadata.size() == 0 && !group.metadatasql.equals("")) {
            group.metadata =
                JdbcUtils.queryForList(
                    group.metadataSqlString.getParseSql(request, this.replaceMap));
          }
          sqlGroupSb.append(group.macrovalue).append(',');
          sqlGroupSelectGroupSb
              .append(group.macrovalue)
              .append(" as ")
              .append(group.groupLabel)
              .append(',');
        }
        sqlGroup = sqlGroupSb.deleteCharAt(sqlGroupSb.length() - 1).toString();
        sqlGroupSelectGroup = sqlGroupSelectGroupSb.toString();
      }
    }
    // 如果不是第1次并配置为第1次不运行
    if (queryValue.runTime == 0 && !firstShow) {
      queryValue.title = new String[0];
    } else {
      queryValue.dataList = new ArrayList();
      queryValue.allDataList = new ArrayList();
      // 进行sqlFromWhere的解析

      sqlConfig.sqlFromWhere = sqlConfig.sqlStringFromWhere.getParseSql(request, this.replaceMap);
      //    sqlConfig.sqlSelect = sqlConfig.sqlStringSelect.getParseSql(request, this.replaceMap);

      if (sqlGroup.length() > 0)
        sqlConfig.sqlData =
            "select "
                + sqlGroupSelectGroup
                + sqlGroupSelect.getSql(request)
                + " "
                + sqlConfig.sqlFromWhere
                + " group by "
                + sqlGroup;
      else {
        sqlConfig.sqlData = "select " + sqlConfig.sqlSelect + " " + sqlConfig.sqlFromWhere;
        sqlConfig.sqlSum = this.sqlSum;
        if (sqlConfig.sqlSum.length() > 0)
          sqlConfig.sqlDataSum = "select " + sqlConfig.sqlSum + " " + sqlConfig.sqlFromWhere;
        sqlConfig.sqlCount =
            "select count(*) from (" + sqlConfig.sqlData + ")"; // + sqlConfig.sqlFromWhere;
        String query_sortcol = RequestUtils.getStringParameter(request, "query_sortcol", "");
        sqlConfig.sqlOrder = this.sqlOrder;
        if (!StringUtils.isBlank(query_sortcol)) {
          sqlConfig.sqlOrder =
              " order by "
                  + query_sortcol
                  + " "
                  + RequestUtils.getStringParameter(request, "query_sortdir", "");
        }
        sqlConfig.sqlOrder = StringUtils.trimToEmpty(sqlConfig.sqlOrder);
      }

      // 从数据库获取数据
      calTime.begin();
      if (needCache
          && agentClass.fetchCacheResultFromDb(eleConfig, sqlConfig, request, queryValue)) {
        int position = queryValue.pageSize * (queryValue.pageNo - 1);
        int maxsize = position + queryValue.pageSize;
        if (queryValue.allDataList.size() <= maxsize) maxsize = queryValue.allDataList.size();
        else {
          queryValue.hasNextPage = true;
        }
        if (queryValue.pageSize == -1) {
          position = 0;
          maxsize = queryValue.allDataList.size();
        }
        for (int i = position; i < maxsize; i++) {
          queryValue.dataList.add(queryValue.allDataList.get(i));
        }
      } else {
        calTimeSub.begin();
        agentClass.fetchPageResultFromDb(eleConfig, sqlConfig, request, queryValue);
        queryValue
            .calTimeSb
            .append("从数据库获取数据时间:")
            .append(calTimeSub.endString())
            .append(StringUtils.LINE_SEPARATOR);
      }
      queryValue
          .calTimeSb
          .append("总共获取数据时间:")
          .append(calTime.endString())
          .append(StringUtils.LINE_SEPARATOR);
    }
    return queryValue;
  }