示例#1
0
  private void createItem(String conteudo, int index, ItemPlanilhaUpload item)
      throws ParseException {

    // formatar a data da planilha para o Obj
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

    // Formatar a Hora da Planilha para o objeto
    SimpleDateFormat shf = new SimpleDateFormat("HH:mm:ss");

    if (index == 0) {
      conteudo = removeHifen(conteudo);
      item.setPlaca(conteudo);
    } else if (index == 4) {
      item.setCategoria(Integer.valueOf(conteudo));
    } else if (index == 5) {
      item.setData(sdf.parse(conteudo));
    } else if (index == 6) {
      item.setHora(shf.parse(conteudo));
    } else if (index == 7) {
      item.setConcessionaria(conteudo);
    } else if (index == 8) {
      item.setPraca(conteudo);
    } else if (index == 9) {
      item.setValor(Double.valueOf(conteudo));
    }
  }
示例#2
0
  private ItemPlanilhaDownload criaItemDownload(
      ItemPlanilhaUpload itemPlanilhaUpload, Veiculo temp, boolean duplicado) {

    ItemPlanilhaDownload item = new ItemPlanilhaDownload();
    item.setCategoria(itemPlanilhaUpload.getCategoria());
    item.setCategoriaCorreta(temp.getMaximoEixo());
    item.setConcessionaria(itemPlanilhaUpload.getConcessionaria());
    item.setData(itemPlanilhaUpload.getData());
    item.setHora(itemPlanilhaUpload.getHora());
    item.setPlaca(itemPlanilhaUpload.getPlaca());
    item.setValor(itemPlanilhaUpload.getValor());
    item.setPraca(itemPlanilhaUpload.getPraca());
    item.setValorCorreto(
        item.getValor()
            / item.formataCategoria(item.getCategoria())
            * item.formataCategoria(item.getCategoriaCorreta()));
    if (duplicado) {
      item.setValorRestituicao(item.getValor());
    } else {
      item.setValorRestituicao(item.getValor() - item.getValorCorreto());
    }
    item.setObs(duplicado ? "Passagem Duplicada" : "Número de Eixos incorreto");
    return item;
  }
示例#3
0
  private List<ItemPlanilhaDownload> lerPlanilha(
      String path, Object workbook, Object sheet, Veiculo veiculo)
      throws IOException, ParseException {

    // formatar a data da planilha para o Obj
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");

    // Formatar a Hora da Planilha para o objeto
    SimpleDateFormat shf = new SimpleDateFormat("HH:mm:ss");

    FileInputStream fisPlanilha = null;

    // Lista de veiculos da planilha
    List<ItemPlanilhaUpload> lista = new ArrayList<ItemPlanilhaUpload>();

    ItemPlanilhaUpload item = new ItemPlanilhaUpload();

    File file = new File(path);
    fisPlanilha = new FileInputStream(file);
    Iterator<Row> rowIterator = null;

    if (workbook instanceof XSSFWorkbook) {
      workbook = new XSSFWorkbook(fisPlanilha);
      sheet = ((XSSFWorkbook) workbook).getSheet("Passagens de Pedágio");
      // retorna todas as linhas da planilha 0 (aba 1)
      rowIterator = ((XSSFSheet) sheet).iterator();
    } else {
      workbook = new HSSFWorkbook(fisPlanilha);
      sheet = ((HSSFWorkbook) workbook).getSheet("Passagens de Pedágio");
      // retorna todas as linhas da planilha 0 (aba 1)
      rowIterator = ((HSSFSheet) sheet).iterator();
    }

    // varre todas as linhas da planilha 0
    while (rowIterator.hasNext()) {

      // recebe cada linha da planilha
      Row row = rowIterator.next();

      if (row.getRowNum() == 0) {
        continue;
      }

      // pegamos todas as celulas desta linha
      Iterator<Cell> cellIterator = row.iterator();

      // varremos todas as celulas da linha atual
      while (cellIterator.hasNext()) {

        // criamos uma celula
        Cell cell = cellIterator.next();

        if (cell.getColumnIndex() == 0) {
          item.setPlaca(cell.getStringCellValue());
        } else if (cell.getColumnIndex() == 2) {
          item.setCategoria(Integer.valueOf(cell.getStringCellValue()));
        } else if (cell.getColumnIndex() == 3) {

          item.setData(sdf.parse(cell.getStringCellValue()));

        } else if (cell.getColumnIndex() == 4) {

          item.setHora(shf.parse(cell.getStringCellValue()));

        } else if (cell.getColumnIndex() == 5) {
          item.setConcessionaria(cell.getStringCellValue());
        } else if (cell.getColumnIndex() == 6) {
          item.setPraca(cell.getStringCellValue());
        }
        if (cell.getColumnIndex() == 7) {
          if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
            item.setValor(cell.getNumericCellValue());
          } else {
            item.setValor(0.0);
          }
          lista.add(item);
          item = new ItemPlanilhaUpload();
        }
      }
    }
    fisPlanilha.close();
    return this.makeTheMagic(lista, veiculo);
  }