Example #1
0
  public void updateSacado(ArrayList<String> linesSacado) {
    String nomeFundo = "";
    String nomeSacado = "";
    String docSacado = "";
    double valorPresente = 0.0;
    double limite = 0.0;
    double concentracao = 0.0;
    double operar = 0.0;
    Statement stmt = null;
    ArrayList<ConcentracaoSacadoIndicador> concentracaoSacado =
        new ArrayList<ConcentracaoSacadoIndicador>();

    int idFundo = 0;
    int idEntidadeSacado = 0;
    FundoDeInvestimento fundo = new FundoDeInvestimento();
    Entidade sacado = new Entidade();

    for (String line : linesSacado) {
      // System.out.println(line);
      String[] field = line.split(";");

      if (field.length > 0) {

        if (nomeFundo.length() == 0
            || !field[0].replace("FIDC_", "").toLowerCase().equals(nomeFundo)) {
          nomeFundo = field[0].replace("FIDC_", "").toLowerCase();
          try {
            stmt = (Statement) UpdateConcentracao.conn.createStatement();
          } catch (SQLException e) {
            e.printStackTrace();
          }
          String query = "Select idEntidade from Entidade where nomeCurto = '" + nomeFundo + "'";
          int idEntidade = 0;
          try {
            ResultSet rs = stmt.executeQuery(query);
            while (rs.next()) {
              idEntidade = rs.getInt("idEntidade");
              //							System.out.println("Fundo: " + nomeFundo + " idEntidade: " + idEntidade);
            }
          } catch (SQLException e) {
            e.printStackTrace();
          }

          query = "Select idFundo from Fundo where idEntidade = " + idEntidade;
          try {
            ResultSet rs = stmt.executeQuery(query);
            while (rs.next()) {
              idFundo = rs.getInt("idFundo");
              System.out.println(
                  "Fundo: " + nomeFundo + " idFundo: " + idFundo + " idEntidade:" + idEntidade);
            }
          } catch (SQLException e) {
            e.printStackTrace();
          }
          fundo = new FundoDeInvestimento(idFundo, conn);
        }

        docSacado = field[3].replace(".", "").replace("/", "").replace("-", "");
        if (nomeSacado.length() == 0 || !field[2].equals(nomeSacado)) {
          nomeSacado = field[2];
          try {
            stmt = (Statement) UpdateConcentracao.conn.createStatement();
          } catch (SQLException e) {
            e.printStackTrace();
          }
          String query = "Select idEntidade from Entidade where nome = '" + nomeSacado + "'";
          idEntidadeSacado = 0;
          try {
            ResultSet rs = stmt.executeQuery(query);
            while (rs.next()) {
              idEntidadeSacado = rs.getInt("idEntidade");
              // System.out.println("Cedente: " + nomeCedente + " idEntidade: " + idEntidade);
            }
          } catch (SQLException e) {
            e.printStackTrace();
          }

          if (idEntidadeSacado == 0) {
            //						System.out.println("Cedente não cadastrado");
            String stringDataCadastro = sdfd.format(Calendar.getInstance().getTime());
            String nomeCurtoSacado = nomeSacado;

            if (nomeSacado.length() > 45) {
              nomeCurtoSacado = nomeSacado.substring(0, 45);
            }
            try {
              int idTipoDeCadastro = 2;
              if (docSacado.length() < 14) {
                idTipoDeCadastro = 1;
              }
              stmt = (Statement) conn.createStatement();
              String sql =
                  "INSERT INTO `MVCapital`.`Entidade` (`nome`,`nomeCurto`,`cadastro`,`dataDeInicio`,`idTipoDeCadastro`) VALUES ('"
                      + nomeSacado
                      + "','"
                      + nomeCurtoSacado
                      + "','"
                      + docSacado
                      + "','"
                      + stringDataCadastro
                      + "',"
                      + idTipoDeCadastro
                      + ")";
              //							System.out.println(sql);
              stmt.executeUpdate(sql);
              //							System.out.println("New Cedente: " + nomeCedente);

              stmt = (Statement) conn.createStatement();
              query = "SELECT idEntidade FROM Entidade WHERE nome ='" + nomeSacado + "'";
              //							System.out.println(query);
              ResultSet rs = stmt.executeQuery(query);
              while (rs.next()) {
                idEntidadeSacado = rs.getInt("idEntidade");
              }

            } catch (SQLException e) {
              e.printStackTrace();
            }
          }

          sacado = new Entidade(idEntidadeSacado, conn);
        }
        valorPresente = Double.parseDouble(field[5].replace(",", "."));
        if (!field[6].isEmpty()) {
          limite = Double.parseDouble(field[6].replace("%", "").replace(",", "."));
        } else {
          limite = 0.0;
        }
        concentracao = Double.parseDouble(field[7].replace("%", "").replace(",", "."));
        operar = Double.parseDouble(field[8].replace(",", "."));
        if (fundo.getNomeCurto().length() > 0) {
          System.out.println(
              fundo.getNomeCurto() + " " + sacado.getNomeCurto() + " " + limite + " " + operar);
          String stringValues =
              idEntidadeSacado
                  + ","
                  + idFundo
                  + ","
                  + valorPresente
                  + ","
                  + limite
                  + ","
                  + concentracao
                  + ","
                  + operar;
          String sql =
              "INSERT INTO `MVCapital`.`ConcentracaoSacado` (`idEntidadeSacado`,`idFundo`,`valorPresente`,`limite`,`concentracao`,`operar`) VALUES ("
                  + stringValues
                  + ")";
          //				System.out.println(sql);
          try {
            stmt.executeUpdate(sql);
          } catch (SQLException e) {
            e.printStackTrace();
          }
          concentracaoSacado.add(
              new ConcentracaoSacadoIndicador(sacado, fundo, valorPresente, concentracao, operar));
        }
      }
    }
  }
Example #2
0
  public void updatePL(ArrayList<String> linesPL) {
    String nomeFundo = "";
    Date dataPL = Calendar.getInstance().getTime();
    double valor = 0.0;

    Statement stmt = null;

    int idFundo = 0;
    FundoDeInvestimento fundo = new FundoDeInvestimento();

    for (String line : linesPL) {
      // System.out.println(line);
      String[] field = line.split(";");

      if (field.length > 0) {
        //				System.out.println(field.length + "\t"+ line);
        if (field.length > 2) {
          if (field[2].length() > 0) {

            nomeFundo = field[2].replace("FIDC_", "").toLowerCase();
            //						System.out.println(nomeFundo);
            if (nomeFundo.length() > 0) {

              try {
                stmt = (Statement) UpdateConcentracao.conn.createStatement();
              } catch (SQLException e) {
                e.printStackTrace();
              }
              String query =
                  "Select idEntidade from Entidade where nomeCurto = '" + nomeFundo + "'";
              //							System.out.println(query);
              int idEntidade = 0;
              try {
                ResultSet rs = stmt.executeQuery(query);
                while (rs.next()) {
                  idEntidade = rs.getInt("idEntidade");
                  //							System.out.println("Fundo: " + nomeFundo + " idEntidade: " + idEntidade);
                }
              } catch (SQLException e) {
                e.printStackTrace();
              }

              query = "Select idFundo from Fundo where idEntidade = " + idEntidade;
              //							System.out.println(query);
              try {
                ResultSet rs = stmt.executeQuery(query);
                while (rs.next()) {
                  idFundo = rs.getInt("idFundo");
                  //									System.out.println("Fundo: " + nomeFundo + " idFundo: " + idFundo + "
                  // idEntidade:" + idEntidade) ;
                }
              } catch (SQLException e) {
                e.printStackTrace();
              }
              fundo = new FundoDeInvestimento(idFundo, conn);
            }
          }
        }
        if (fundo.getNomeCurto().length() > 0) {
          if (field.length > 1) {
            if (field[0].length() > 0 && field[1].length() > 0) {
              try {
                dataPL = sdfd.parse(field[0]);
              } catch (ParseException e1) {
                e1.printStackTrace();
              }
              valor = Double.parseDouble(field[1].replace(".", "").replace(",", "."));
              System.out.println(fundo.getNomeCurto() + " " + sdfd.format(dataPL) + " " + valor);
              String stringValues = idFundo + ",'" + sdfd.format(dataPL) + "'," + valor;
              String sql =
                  "INSERT INTO `mvcapital`.`PLFundo` (`idFundo`,`data`,`valor`) VALUES ("
                      + stringValues
                      + ")";
              //							System.out.println(sql);
              try {
                stmt.executeUpdate(sql);
              } catch (SQLException e) {
                e.printStackTrace();
              }
            }
          }
        }
      }
    }
  }