public void avalia(
      DocumentHTML document, HttpServletRequest request, HttpServletResponse response)
      throws Exception {
    UsuarioDTO usuarioDto = WebUtil.getUsuario(request);
    if (usuarioDto == null) {
      document.alert(UtilI18N.internacionaliza(request, "citcorpore.comum.sessaoExpirada"));
      document.executeScript(
          "window.location = '"
              + Constantes.getValue("SERVER_ADDRESS")
              + request.getContextPath()
              + "'");
      return;
    }
    AcordoNivelServicoService acordoNivelServicoService =
        (AcordoNivelServicoService)
            ServiceLocator.getInstance().getService(AcordoNivelServicoService.class, null);
    RequisitoSLAService requisitoSLAService =
        (RequisitoSLAService)
            ServiceLocator.getInstance().getService(RequisitoSLAService.class, null);
    Collection colAcordos = acordoNivelServicoService.findAcordosSemVinculacaoDireta();
    Collection colReqs = requisitoSLAService.list();

    ControleGenerateSLAPorRequisitoSLA controleGenerateSLAPorRequisitoSLA =
        new ControleGenerateSLAPorRequisitoSLA();
    ControleGenerateSLAPorRequisitoSLAEmAndamento controleGenerateSLAPorRequisitoSLAEmAndamento =
        new ControleGenerateSLAPorRequisitoSLAEmAndamento();
    String table = "<table border='1'>";
    if (colAcordos != null && colAcordos.size() > 0) {
      table += "<tr>";
      table += "<td>";
      table += "<b>" + UtilI18N.internacionaliza(request, "sla.avaliacao.acordo") + "</b>";
      table += "</td>";
      table += "</tr>";
      table += "<tr>";
      table += "<td>";
      table += "&nbsp;";
      table += "</td>";
      table += "</tr>";
      for (Iterator it = colAcordos.iterator(); it.hasNext(); ) {
        AcordoNivelServicoDTO acordoNivelServicoDTO = (AcordoNivelServicoDTO) it.next();
        table += "<tr>";
        table += "<td colspan='5' style='background-color:gray'>";
        table +=
            UtilI18N.internacionaliza(request, "citcorpore.comum.acordo")
                + ": <b>"
                + acordoNivelServicoDTO.getTituloSLA()
                + "</b>";
        table += "</td>";
        table += "</tr>";
        if (acordoNivelServicoDTO.getTipo().equalsIgnoreCase("T")) {
          table +=
              generateSLATime(
                  document,
                  request,
                  acordoNivelServicoDTO,
                  acordoNivelServicoDTO.getIdAcordoNivelServico(),
                  usuarioDto);
          table +=
              generateAvailSLATime(
                  document,
                  request,
                  acordoNivelServicoDTO,
                  acordoNivelServicoDTO.getIdAcordoNivelServico(),
                  usuarioDto);
        } else if (acordoNivelServicoDTO.getTipo().equalsIgnoreCase("D")) {
          table +=
              generateAvailSLAAvailability(
                  document,
                  request,
                  response,
                  acordoNivelServicoDTO,
                  acordoNivelServicoDTO.getIdAcordoNivelServico(),
                  usuarioDto);
        }
      }
    }
    if (colReqs != null && colReqs.size() > 0) {
      table += "<tr>";
      table += "<td>";
      table += "&nbsp;";
      table += "</td>";
      table += "</tr>";
      table += "<tr>";
      table += "<td>";
      table += "<b>" + UtilI18N.internacionaliza(request, "sla.avaliacao.requisito") + "</b>";
      table += "</td>";
      table += "</tr>";
      for (Iterator it = colReqs.iterator(); it.hasNext(); ) {
        RequisitoSLADTO requisitoSLADTO = (RequisitoSLADTO) it.next();
        List lst = controleGenerateSLAPorRequisitoSLA.execute(requisitoSLADTO.getIdRequisitoSLA());
        double qtdeDentroPrazo = 0;
        double qtdeForaPrazo = 0;
        if (lst != null && lst.size() > 0) {
          for (Iterator itSLA = lst.iterator(); itSLA.hasNext(); ) {
            Object[] objs = (Object[]) itSLA.next();
            if (((String) objs[0]).indexOf("Fora") > -1 || ((String) objs[0]).indexOf("Out") > -1) {
              qtdeForaPrazo = (Double) objs[2];
            } else {
              qtdeDentroPrazo = (Double) objs[2];
            }
          }
        }
        double qtdeDentroPrazoPerc = (qtdeDentroPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100;
        double qtdeForaPrazoPerc = (qtdeForaPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100;

        final DefaultValueDataset dataset =
            new DefaultValueDataset(new Double(qtdeDentroPrazoPerc));

        // create the chart...
        final ThermometerPlot plot = new ThermometerPlot(dataset);
        final JFreeChart chart =
            new JFreeChart(
                UtilI18N.internacionaliza(request, "sla.avaliacao.avaliacaogeral"), // chart title
                JFreeChart.DEFAULT_TITLE_FONT,
                plot, // plot
                false); // include legend

        plot.setSubrangeInfo(ThermometerPlot.NORMAL, 90.000001, 100);
        plot.setSubrangeInfo(ThermometerPlot.WARNING, 80.000001, 90);
        plot.setSubrangeInfo(ThermometerPlot.CRITICAL, 0, 80);

        plot.setThermometerStroke(new BasicStroke(2.0f));
        plot.setThermometerPaint(Color.lightGray);

        String nomeImgAval =
            CITCorporeUtil.caminho_real_app
                + "/tempFiles/"
                + usuarioDto.getIdUsuario()
                + "/avalREQSLA_"
                + requisitoSLADTO.getIdRequisitoSLA()
                + ".png";
        String nomeImgAvalRel =
            br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS")
                + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO")
                + "/tempFiles/"
                + usuarioDto.getIdUsuario()
                + "/avalREQSLA_"
                + requisitoSLADTO.getIdRequisitoSLA()
                + ".png";
        File arquivo = new File(nomeImgAval);

        if (arquivo.exists()) {
          arquivo.delete();
        } else {
          String nomeDir =
              CITCorporeUtil.caminho_real_app + "/tempFiles/" + usuarioDto.getIdUsuario() + "/";
          File dirTemp = new File(nomeDir);
          dirTemp.mkdirs();
          arquivo.createNewFile();
        }

        ChartUtilities.saveChartAsPNG(arquivo, chart, 500, 200);

        List lst2 =
            controleGenerateSLAPorRequisitoSLAEmAndamento.execute(
                requisitoSLADTO.getIdRequisitoSLA());
        qtdeDentroPrazo = 0;
        qtdeForaPrazo = 0;
        if (lst2 != null && lst2.size() > 0) {
          for (Iterator itSLA = lst2.iterator(); itSLA.hasNext(); ) {
            Object[] objs = (Object[]) itSLA.next();
            if (((String) objs[0]).indexOf("Fora") > -1 || ((String) objs[0]).indexOf("Out") > -1) {
              qtdeForaPrazo = (Double) objs[2];
            } else {
              qtdeDentroPrazo = (Double) objs[2];
            }
          }
        }
        qtdeDentroPrazoPerc = (qtdeDentroPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100;
        qtdeForaPrazoPerc = (qtdeForaPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100;

        DefaultPieDataset datasetPie = new DefaultPieDataset();
        datasetPie.setValue(
            UtilI18N.internacionaliza(request, "sla.avaliacao.noprazo")
                + " ("
                + UtilFormatacao.formatDouble(qtdeDentroPrazo, 0)
                + ")",
            new Double(qtdeDentroPrazoPerc));
        datasetPie.setValue(
            UtilI18N.internacionaliza(request, "sla.avaliacao.foraprazo")
                + " ("
                + UtilFormatacao.formatDouble(qtdeForaPrazo, 0)
                + ")",
            new Double(qtdeForaPrazoPerc));

        JFreeChart chartX =
            ChartFactory.createPieChart(
                UtilI18N.internacionaliza(request, "sla.avaliacao.emandamento"), // chart title
                datasetPie, // data
                true, // include legend
                false,
                false);

        PiePlot plotPie = (PiePlot) chartX.getPlot();
        plotPie.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
        plotPie.setNoDataMessage(UtilI18N.internacionaliza(request, "sla.avaliacao.naohadados"));
        plotPie.setCircular(false);
        plotPie.setLabelGap(0.02);

        String nomeImgAval2 =
            CITCorporeUtil.caminho_real_app
                + "/tempFiles/"
                + usuarioDto.getIdUsuario()
                + "/avalREQSLA2_"
                + requisitoSLADTO.getIdRequisitoSLA()
                + ".png";
        String nomeImgAvalRel2 =
            br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS")
                + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO")
                + "/tempFiles/"
                + usuarioDto.getIdUsuario()
                + "/avalREQSLA2_"
                + requisitoSLADTO.getIdRequisitoSLA()
                + ".png";
        File arquivo2 = new File(nomeImgAval2);
        if (arquivo2.exists()) {
          arquivo2.delete();
        }
        ChartUtilities.saveChartAsPNG(arquivo2, chartX, 200, 200);

        table += "<tr>";
        table += "<td style='border:1px solid black; vertical-align:middle;'>";
        table += UtilHTML.encodeHTML(UtilStrings.retiraApostrofe(requisitoSLADTO.getAssunto()));
        table += "</td>";
        table += "<td style='border:1px solid black; vertical-align:middle;'>";
        if (requisitoSLADTO.getSituacao() != null
            && requisitoSLADTO.getSituacao().equalsIgnoreCase("A")) {
          table +=
              "<img src='"
                  + br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS")
                  + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO")
                  + "/imagens/bolaverde.png' border='0'  title='"
                  + UtilI18N.internacionaliza(request, "requisitosla.ativo")
                  + "'/>";
          table += UtilI18N.internacionaliza(request, "requisitosla.ativo");
        } else if (requisitoSLADTO.getSituacao() != null
            && requisitoSLADTO.getSituacao().equalsIgnoreCase("P")) {
          table +=
              "<img src='"
                  + br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS")
                  + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO")
                  + "/imagens/bolavermelha.png' border='0'  title='"
                  + UtilI18N.internacionaliza(request, "requisitosla.planejamento")
                  + "'/>";
          table += UtilI18N.internacionaliza(request, "requisitosla.planejamento");
        } else if (requisitoSLADTO.getSituacao() != null
            && requisitoSLADTO.getSituacao().equalsIgnoreCase("R")) {
          table +=
              "<img src='"
                  + br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS")
                  + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO")
                  + "/imagens/bolavermelha.png' border='0'  title='"
                  + UtilI18N.internacionaliza(request, "requisitosla.emrevisao")
                  + "'/>";
          table += UtilI18N.internacionaliza(request, "requisitosla.emrevisao");
        } else {
          table +=
              "<img src='"
                  + br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS")
                  + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO")
                  + "/imagens/bolavermelha.png' border='0'  title='"
                  + UtilI18N.internacionaliza(request, "requisitosla.inativo")
                  + "'/>";
          table += UtilI18N.internacionaliza(request, "requisitosla.inativo");
        }
        table += "</td>";
        table += "<td style='border:1px solid black'>";
        table += "<img src='" + nomeImgAvalRel + "' border='0'/>";
        table += "</td>";
        table += "<td style='border:1px solid black'>";
        table += "<img src='" + nomeImgAvalRel2 + "' border='0'/>";
        table += "</td>";
        table += "</tr>";
      }
    }
    table += "</table>";
    document.getElementById("divInfo").setInnerHTML(table);
  }
  private String generateAvailSLATime(
      DocumentHTML document,
      HttpServletRequest request,
      AcordoNivelServicoDTO acordoNivelServicoDTO,
      Integer idAcordoNivelServico,
      UsuarioDTO usuarioDto)
      throws IOException, ParseException {
    SlaAvaliacaoDTO slaAvaliacaoDto = (SlaAvaliacaoDTO) document.getBean();
    ControleGenerateSLAPorAcordoNivelServico controleGenerateSLAPorAcordoNivelServico =
        new ControleGenerateSLAPorAcordoNivelServico();
    ControleGenerateSLAPorAcordoNivelServicoEmAndamento
        controleGenerateSLAPorAcordoNivelServicoEmAndamento =
            new ControleGenerateSLAPorAcordoNivelServicoEmAndamento();
    List lst =
        controleGenerateSLAPorAcordoNivelServico.execute(
            idAcordoNivelServico, slaAvaliacaoDto.getDataInicio(), slaAvaliacaoDto.getDataFim());
    double qtdeDentroPrazo = 0;
    double qtdeForaPrazo = 0;
    if (lst != null && lst.size() > 0) {
      for (Iterator itSLA = lst.iterator(); itSLA.hasNext(); ) {
        Object[] objs = (Object[]) itSLA.next();
        if (((String) objs[0]).indexOf("Fora") > -1 || ((String) objs[0]).indexOf("Out") > -1) {
          qtdeForaPrazo = (Double) objs[2];
        } else {
          qtdeDentroPrazo = (Double) objs[2];
        }
      }
    }
    double qtdeDentroPrazoPerc = (qtdeDentroPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100;
    double qtdeForaPrazoPerc = (qtdeForaPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100;

    final DefaultValueDataset dataset = new DefaultValueDataset(new Double(qtdeDentroPrazoPerc));

    // create the chart...
    final ThermometerPlot plot = new ThermometerPlot(dataset);
    final JFreeChart chart =
        new JFreeChart(
            UtilI18N.internacionaliza(request, "sla.avaliacao.avaliacaogeral"), // chart title
            JFreeChart.DEFAULT_TITLE_FONT,
            plot, // plot
            false); // include legend

    plot.setSubrangeInfo(ThermometerPlot.NORMAL, 90.000001, 100);
    plot.setSubrangeInfo(ThermometerPlot.WARNING, 80.000001, 90);
    plot.setSubrangeInfo(ThermometerPlot.CRITICAL, 0, 80);

    plot.setThermometerStroke(new BasicStroke(2.0f));
    plot.setThermometerPaint(Color.lightGray);

    String nomeImgAval =
        CITCorporeUtil.caminho_real_app
            + "/tempFiles/"
            + usuarioDto.getIdUsuario()
            + "/avalSLA_"
            + acordoNivelServicoDTO.getIdAcordoNivelServico()
            + ".png";
    String nomeImgAvalRel =
        br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS")
            + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO")
            + "/tempFiles/"
            + usuarioDto.getIdUsuario()
            + "/avalSLA_"
            + acordoNivelServicoDTO.getIdAcordoNivelServico()
            + ".png";
    File arquivo = new File(nomeImgAval);

    if (arquivo.exists()) {
      arquivo.delete();
    } else {
      String nomeDir =
          CITCorporeUtil.caminho_real_app + "/tempFiles/" + usuarioDto.getIdUsuario() + "/";
      File dirTemp = new File(nomeDir);
      dirTemp.mkdirs();
      arquivo.createNewFile();
    }

    ChartUtilities.saveChartAsPNG(arquivo, chart, 500, 200);

    List lst2 = controleGenerateSLAPorAcordoNivelServicoEmAndamento.execute(idAcordoNivelServico);
    qtdeDentroPrazo = 0;
    qtdeForaPrazo = 0;
    if (lst2 != null && lst2.size() > 0) {
      for (Iterator itSLA = lst2.iterator(); itSLA.hasNext(); ) {
        Object[] objs = (Object[]) itSLA.next();
        if (((String) objs[0]).indexOf("Fora") > -1 || ((String) objs[0]).indexOf("Out") > -1) {
          qtdeForaPrazo = (Double) objs[2];
        } else {
          qtdeDentroPrazo = (Double) objs[2];
        }
      }
    }
    qtdeDentroPrazoPerc = (qtdeDentroPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100;
    qtdeForaPrazoPerc = (qtdeForaPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100;

    DefaultPieDataset datasetPie = new DefaultPieDataset();
    datasetPie.setValue(
        UtilI18N.internacionaliza(request, "sla.avaliacao.noprazo")
            + " ("
            + UtilFormatacao.formatDouble(qtdeDentroPrazo, 0)
            + ")",
        new Double(qtdeDentroPrazoPerc));
    datasetPie.setValue(
        UtilI18N.internacionaliza(request, "sla.avaliacao.foraprazo")
            + " ("
            + UtilFormatacao.formatDouble(qtdeForaPrazo, 0)
            + ")",
        new Double(qtdeForaPrazoPerc));

    JFreeChart chartX =
        ChartFactory.createPieChart(
            UtilI18N.internacionaliza(request, "sla.avaliacao.emandamento"), // chart title
            datasetPie, // data
            true, // include legend
            true,
            false);

    PiePlot plotPie = (PiePlot) chartX.getPlot();
    plotPie.setLabelFont(new Font("SansSerif", Font.PLAIN, 6));
    plotPie.setNoDataMessage(UtilI18N.internacionaliza(request, "sla.avaliacao.naohadados"));
    plotPie.setCircular(true);
    plotPie.setLabelGap(0);

    String nomeImgAval2 =
        CITCorporeUtil.caminho_real_app
            + "/tempFiles/"
            + usuarioDto.getIdUsuario()
            + "/avalSLA2_"
            + idAcordoNivelServico
            + ".png";
    String nomeImgAvalRel2 =
        br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS")
            + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO")
            + "/tempFiles/"
            + usuarioDto.getIdUsuario()
            + "/avalSLA2_"
            + idAcordoNivelServico
            + ".png";
    File arquivo2 = new File(nomeImgAval2);
    if (arquivo2.exists()) {
      arquivo2.delete();
    }
    ChartUtilities.saveChartAsPNG(arquivo2, chartX, 200, 200);

    String table = "";
    table += "<tr>";
    table += "<td style='border:1px solid black; vertical-align:middle;'>";
    // table +=
    // UtilHTML.encodeHTML(UtilStrings.retiraApostrofe(acordoNivelServicoDTO.getTituloSLA()));
    table +=
        "<br>"
            + geraTabelaMeses(
                acordoNivelServicoDTO.getTituloSLA(), idAcordoNivelServico, request, usuarioDto);
    table += "</td>";
    table += "<td style='border:1px solid black; vertical-align:middle;'>";
    if (acordoNivelServicoDTO.getTipo() != null
        && acordoNivelServicoDTO.getTipo().equalsIgnoreCase("T")) {
      table +=
          "<img src='"
              + br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS")
              + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO")
              + "/imagens/relogio.png' border='0'  title='"
              + UtilI18N.internacionaliza(request, "sla.avaliacao.tempo")
              + "'/>";
      table += UtilI18N.internacionaliza(request, "sla.avaliacao.tempo");
    } else if (acordoNivelServicoDTO.getTipo() != null
        && acordoNivelServicoDTO.getTipo().equalsIgnoreCase("D")) {
      table +=
          "<img src='"
              + br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS")
              + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO")
              + "/imagens/disponibilidade.png' border='0'  title='"
              + UtilI18N.internacionaliza(request, "sla.avaliacao.disponibilidade")
              + "'/>";
      table += UtilI18N.internacionaliza(request, "sla.avaliacao.disponibilidade");
    } else if (acordoNivelServicoDTO.getTipo() != null
        && acordoNivelServicoDTO.getTipo().equalsIgnoreCase("V")) {
      table +=
          "<img src='"
              + br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS")
              + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO")
              + "/imagens/outrasfontes.png' border='0'  title='"
              + UtilI18N.internacionaliza(request, "sla.avaliacao.outrasfontes")
              + "'/>";
      table += UtilI18N.internacionaliza(request, "sla.avaliacao.outrasfontes");
    }
    table += "</td>";
    table += "<td style='border:1px solid black; vertical-align:middle;'>";
    if (acordoNivelServicoDTO.getDataFim() != null
        && acordoNivelServicoDTO.getDataFim().before(UtilDatas.getDataAtual())) {
      table +=
          "<img src='"
              + br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS")
              + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO")
              + "/imagens/bolavermelha.png' border='0'  title='"
              + UtilI18N.internacionaliza(request, "sla.avaliacao.inativo")
              + "'/>";
      table += UtilI18N.internacionaliza(request, "sla.avaliacao.inativo");
    } else {
      table +=
          "<img src='"
              + br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS")
              + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO")
              + "/imagens/bolaverde.png' border='0'  title='"
              + UtilI18N.internacionaliza(request, "sla.avaliacao.ativo")
              + "'/>";
      table += UtilI18N.internacionaliza(request, "sla.avaliacao.ativo");
    }
    table += "</td>";
    table += "<td style='border:1px solid black'>";
    table += "<img src='" + nomeImgAvalRel + "' border='0'/>";
    table += "</td>";
    table += "<td style='border:1px solid black'>";
    table += "<img src='" + nomeImgAvalRel2 + "' border='0'/>";
    table += "</td>";
    table += "</tr>";

    return table;
  }
  private String geraTabelaMeses(
      String tituloSLA,
      Integer idAcordoNivelServico,
      HttpServletRequest request,
      UsuarioDTO usuarioDto)
      throws ParseException, IOException {
    ControleGenerateSLAPorAcordoNivelServicoByMesAno
        controleGenerateSLAPorAcordoNivelServicoByMesAno =
            new ControleGenerateSLAPorAcordoNivelServicoByMesAno();
    int m = UtilDatas.getMonth(UtilDatas.getDataAtual());
    int y = UtilDatas.getYear(UtilDatas.getDataAtual());
    int mPesq = (m + 1); // Faz este incremento de 1, pois logo que entrar no laço, faz um -1
    String strTable = "<table width='100%' border='1'>";
    String strHeader = "";
    String strDados = "";
    strHeader += "<tr>";
    strDados += "<tr>";

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    for (int i = 0; i < 6; i++) {
      mPesq = (mPesq - 1);
      if (mPesq <= 0) {
        mPesq = 12;
        y = y - 1;
      }
      strHeader = strHeader + "<td colspan='2' style='border:1px solid black; text-align:center'>";
      strHeader = strHeader + (mPesq + "/" + y);
      strHeader = strHeader + "</td>";

      List lst =
          controleGenerateSLAPorAcordoNivelServicoByMesAno.execute(idAcordoNivelServico, y, mPesq);
      double qtdeDentroPrazo = 0;
      double qtdeForaPrazo = 0;
      if (lst != null && lst.size() > 0) {
        for (Iterator itSLA = lst.iterator(); itSLA.hasNext(); ) {
          Object[] objs = (Object[]) itSLA.next();
          if (((String) objs[0]).indexOf("Fora") > -1 || ((String) objs[0]).indexOf("Out") > -1) {
            qtdeForaPrazo = (Double) objs[2];
          } else {
            qtdeDentroPrazo = (Double) objs[2];
          }
        }
      }
      double qtdeDentroPrazoPerc = 0;
      if ((qtdeDentroPrazo + qtdeForaPrazo) > 0) {
        qtdeDentroPrazoPerc = (qtdeDentroPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100;
      }
      double qtdeForaPrazoPerc = 0;
      if ((qtdeDentroPrazo + qtdeForaPrazo) > 0) {
        qtdeForaPrazoPerc = (qtdeForaPrazo / (qtdeDentroPrazo + qtdeForaPrazo)) * 100;
      }
      strDados = strDados + "<td style='border:1px solid black'>";
      strDados = strDados + UtilFormatacao.formatDouble(qtdeDentroPrazoPerc, 2) + "%";
      strDados = strDados + "</td>";
      strDados = strDados + "<td style='border:1px solid black'>";
      strDados = strDados + UtilFormatacao.formatDouble(qtdeForaPrazoPerc, 2) + "%";
      strDados = strDados + "</td>";

      dataset.setValue(
          new Double(qtdeDentroPrazoPerc),
          UtilI18N.internacionaliza(request, "sla.avaliacao.noprazo"),
          "" + (mPesq + "/" + y));
      dataset.setValue(
          new Double(qtdeForaPrazoPerc),
          UtilI18N.internacionaliza(request, "sla.avaliacao.foraprazo"),
          "" + (mPesq + "/" + y));
    }
    strHeader += "</tr>";
    strDados += "</tr>";

    // create the chart...
    JFreeChart chart =
        ChartFactory.createBarChart(
            tituloSLA, // chart title
            UtilI18N.internacionaliza(request, "sla.avaliacao.indicadores"), // domain axis label
            UtilI18N.internacionaliza(request, "sla.avaliacao.resultado"), // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
            );

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    CategoryPlot plot = chart.getCategoryPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainGridlinesVisible(true);
    plot.setRangeGridlinePaint(Color.white);

    // set the range axis to display integers only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // disable bar outlines...
    BarRenderer renderer = (BarRenderer) plot.getRenderer();
    renderer.setDrawBarOutline(false);

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(0, 64, 0));

    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);

    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setCategoryLabelPositions(
        CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));

    String nomeImgAval =
        CITCorporeUtil.caminho_real_app
            + "/tempFiles/"
            + usuarioDto.getIdUsuario()
            + "/avalSLAXX_"
            + idAcordoNivelServico
            + ".png";
    String nomeImgAvalRel =
        br.com.citframework.util.Constantes.getValue("SERVER_ADDRESS")
            + br.com.citframework.util.Constantes.getValue("CONTEXTO_APLICACAO")
            + "/tempFiles/"
            + usuarioDto.getIdUsuario()
            + "/avalSLAXX_"
            + idAcordoNivelServico
            + ".png";
    File arquivo2 = new File(nomeImgAval);
    if (arquivo2.exists()) {
      arquivo2.delete();
    }
    ChartUtilities.saveChartAsPNG(arquivo2, chart, 500, 200);
    strTable += "<tr>";
    strTable += "<td colspan='12'>";
    strTable += "<img src='" + nomeImgAvalRel + "' border='0'/>";
    strTable += "</td>";
    strTable += "</tr>";

    strTable += strHeader;
    strTable += strDados;

    strTable += "</table>";
    return strTable;
  }
  @SuppressWarnings({"rawtypes", "unchecked"})
  public List processLookup(LookupDTO lookupObject) throws LogicException, Exception {
    StringBuilder sql = new StringBuilder();
    String camposDesejados = "";
    String where = "";

    LookupFieldUtil lookUpField = new LookupFieldUtil();
    Collection colCamposRet = lookUpField.getCamposRetorno(lookupObject.getNomeLookup());
    Iterator itRet = colCamposRet.iterator();
    Campo cp;

    // Os valores que podem ser consultados sao os referentes a:
    // itemConfiguracao, tipoItemConfiguracao, caracteristica e valor.
    while (itRet.hasNext()) {
      cp = (Campo) itRet.next();
      if (!camposDesejados.equalsIgnoreCase("")) {
        camposDesejados = camposDesejados + ",";
      }
      camposDesejados = camposDesejados + cp.getNomeFisico();
    }

    // Montando sql de busca
    sql.append("SELECT " + camposDesejados + " ");
    sql.append("FROM " + lookUpField.getTabela(lookupObject.getNomeLookup()) + " ");
    sql.append(
        "INNER JOIN tipoitemconfiguracao tipo ON item.idtipoitemconfiguracao = tipo.idtipoitemconfiguracao ");
    sql.append(
        "INNER JOIN tipoitemcfgcaracteristica tipocaracteristica ON tipo.idtipoitemconfiguracao = tipocaracteristica.idtipoitemconfiguracao ");
    sql.append(
        "INNER JOIN caracteristica caracteristica ON tipocaracteristica.idcaracteristica = caracteristica.idcaracteristica ");
    sql.append(
        "INNER JOIN valor valor ON caracteristica.idcaracteristica = valor.idcaracteristica AND valor.iditemconfiguracao = item.iditemconfiguracao ");
    sql.append(
        "INNER JOIN itemconfiguracao itempai ON itempai.iditemconfiguracao = item.iditemconfiguracaopai ");

    Collection colCamposPesq = lookUpField.getCamposPesquisa(lookupObject.getNomeLookup());
    Iterator itPesq = colCamposPesq.iterator();
    String obj = null;
    int count = 1;
    while (itPesq.hasNext()) {
      cp = (Campo) itPesq.next();
      obj = null;
      obj = this.getValueParmLookup(lookupObject, count);
      if (obj != null) {
        String[] trataGetNomeFisico = cp.getNomeFisico().split("\\.");
        String nomeFisico = cp.getNomeFisico();
        if (trataGetNomeFisico.length > 1) {
          cp.setNomeFisico(trataGetNomeFisico[1]);
          nomeFisico = trataGetNomeFisico[0] + "." + trataGetNomeFisico[1];
        }
        if (!obj.equalsIgnoreCase("")) {
          if (!where.equalsIgnoreCase("")) {
            where = where + " AND ";
          }
          if (cp.getType().equalsIgnoreCase(Constantes.getValue("FIELDTYPE_TEXT").trim())
              || cp.getType().equalsIgnoreCase(Constantes.getValue("FIELDTYPE_TEXTAREA").trim())) {
            String func = Constantes.getValue("FUNCAO_CONVERTE_MAIUSCULO");
            if (func != null && !func.trim().equalsIgnoreCase("")) {
              // Se for IP, USUARIO ou MAQUINA devera' ser verificado no mesmo campo do itempai.
              if (nomeFisico.equalsIgnoreCase("IP")
                  || nomeFisico.equalsIgnoreCase("USUARIO")
                  || nomeFisico.equalsIgnoreCase("MAQUINA")) {
                where = where + func + "(itempai.identificacao)";
              } else if (nomeFisico.equalsIgnoreCase("CARACTERISTICA")) {
                where = where + func + "(caracteristica.nomecaracteristica)";
              } else if (nomeFisico.equalsIgnoreCase("ITEM")) {
                where = where + func + "(item.identificacao)";
              } else if (nomeFisico.equalsIgnoreCase("UNIDADE")) {
                where = where + func + "(item.idunidade)";
              } else if (nomeFisico.equalsIgnoreCase("TIPO")) {
                where = where + func + "(tipo.nometipoitemconfiguracao)";
              } else {
                where = where + func + "(" + nomeFisico + ")";
              }
            } else {
              where = where + cp.getNomeFisico();
            }
            where = where + " LIKE '%";
          } else {
            if (cp.getType().equalsIgnoreCase(Constantes.getValue("FIELDTYPE_COMBO").trim())) {
              where = where + cp.getNomeFisico();
              where = where + " IN (";
            } else if (cp.getType().equalsIgnoreCase("DATE")) {
              where = where + cp.getNomeFisico();
              where = where + " = '";
            } else {
              where = where + cp.getNomeFisico();
              where = where + " = ";
            }
          }

          if (StringUtils.contains(obj, "'")) {
            obj = StringUtils.replace(obj, "'", "\\'");
          }

          where = where + obj;
          if (cp.getType().equalsIgnoreCase(Constantes.getValue("FIELDTYPE_TEXT").trim())
              || cp.getType().equalsIgnoreCase(Constantes.getValue("FIELDTYPE_TEXTAREA").trim())) {
            where = where + "%'";
          } else if (cp.getType().equalsIgnoreCase("DATE")) {
            where = where + "'";
          } else if (cp.getType().equalsIgnoreCase(Constantes.getValue("FIELDTYPE_COMBO").trim())) {
            where = where + ")";
          }
        }
      }
      count++;
    }

    String strAux;
    if (!where.equalsIgnoreCase("")) {
      sql.append(" WHERE " + where);
      strAux = lookUpField.getWhere(lookupObject.getNomeLookup());
      if (!strAux.equalsIgnoreCase("")) {
        sql.append(" AND ");
        sql.append(strAux);
      }
    } else {
      strAux = lookUpField.getWhere(lookupObject.getNomeLookup());
      if (!strAux.equalsIgnoreCase("")) {
        sql.append(" WHERE " + strAux);
      }
    }

    Collection colCamposOrd = lookUpField.getCamposOrdenacao(lookupObject.getNomeLookup());
    Iterator itOrd = colCamposOrd.iterator();
    String ordem = "";
    while (itOrd.hasNext()) {
      cp = (Campo) itOrd.next();
      if (!ordem.equalsIgnoreCase("")) {
        ordem = ordem + ",";
      }
      ordem = ordem + cp.getNomeFisico();
    }

    if (!ordem.equalsIgnoreCase("")) {
      sql.append(" ORDER BY " + ordem);
    }

    sql.append(" LIMIT 0,400");

    String sqlFinal = sql.toString().toUpperCase();

    List lista = execSQL(sqlFinal, null);
    if (lista == null || lista.size() == 0) {
      TransactionControler tc = this.getTransactionControler();
      if (tc != null) {
        tc.close();
      }

      return null;
    }

    // Processa o resultado.
    List result = new ArrayList<>();
    if (lista == null || lista.size() == 0) {
      TransactionControler tc = this.getTransactionControler();
      if (tc != null) {
        tc.close();
      }

      return result;
    }
    if (lista.size() > 400) {
      TransactionControler tc = this.getTransactionControler();
      if (tc != null) {
        tc.close();
      }

      throw new LogicException(
          "A consulta retornou mais de 400 registros, por favor, especifique melhor a consulta!");
    }
    Iterator it = lista.iterator();
    Campo campoAux;
    int i;
    Collection colAux;
    Object auxObj;
    while (it.hasNext()) {
      Object[] row = (Object[]) it.next();
      itRet = colCamposRet.iterator();
      i = 0;
      campoAux = null;
      colAux = new ArrayList<>();
      while (itRet.hasNext()) {
        cp = (Campo) itRet.next();
        campoAux =
            new Campo(
                cp.getNomeFisico(),
                cp.getDescricao(),
                cp.isObrigatorio(),
                cp.getType(),
                cp.getTamanho());
        if (cp.getType().equalsIgnoreCase(Constantes.getValue("FIELDTYPE_TEXT").trim())
            || cp.getType().equalsIgnoreCase(Constantes.getValue("FIELDTYPE_TEXTAREA").trim())) {
          if (row[i] == null) {
            auxObj = new String("");
          } else {
            String str = new String(row[i].toString());
            auxObj = str.replaceAll("\"", "&quot;").replaceAll("'", "&#180;");
          }
          campoAux.setObjValue(auxObj);
        } else if (cp.getType().equalsIgnoreCase(Constantes.getValue("FIELDTYPE_DATE").trim())) {
          if (row[i] == null) {
            campoAux.setObjValue(null);
          } else {
            auxObj = row[i];
            if ((auxObj instanceof java.sql.Date)) {
              campoAux.setObjValue(UtilDatas.dateToSTR((java.sql.Date) auxObj));
            } else if ((auxObj instanceof java.sql.Timestamp)) {
              campoAux.setObjValue(UtilDatas.dateToSTR((java.sql.Timestamp) auxObj));
            } else {
              campoAux.setObjValue(auxObj.toString());
            }
          }
        } else if (cp.getType().equalsIgnoreCase(Constantes.getValue("FIELDTYPE_MOEDA").trim())) {
          if (row[i] == null) {
            campoAux.setObjValue(null);
          } else {
            auxObj = row[i];
            String valorTransf = null;
            if ((auxObj instanceof Double)) {
              valorTransf =
                  UtilFormatacao.formatBigDecimal(
                      new BigDecimal(((Double) auxObj).doubleValue()), 2);
            } else if ((auxObj instanceof BigDecimal)) {
              valorTransf = UtilFormatacao.formatBigDecimal(((BigDecimal) auxObj), 2);
            } else {
              valorTransf = auxObj.toString();
            }
            campoAux.setObjValue(valorTransf);
          }
        }
        colAux.add(campoAux);
        i++;
      }
      result.add(colAux);
    }

    TransactionControler tc = this.getTransactionControler();
    if (tc != null) {
      tc.close();
    }

    return result;
  }