refactor: organiza imports e simplifica funções em diversos arquivos
This commit is contained in:
@@ -3,7 +3,7 @@ use crate::domain::services::parser_monetario::formatar_valor_br;
|
||||
use chrono::{DateTime, Local};
|
||||
use genpdf::{
|
||||
elements::{Break, Paragraph},
|
||||
fonts, style, Document, Element, SimplePageDecorator,
|
||||
fonts, style, Document, SimplePageDecorator,
|
||||
};
|
||||
use std::path::Path;
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
use rusqlite::Connection;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
const LIMITE_50MB: u64 = 50 * 1024 * 1024;
|
||||
|
||||
/// Determina o caminho do banco de dados conforme o sistema operacional.
|
||||
pub fn caminho_banco() -> PathBuf {
|
||||
let config_dir = dirs::config_dir().unwrap_or_else(|| PathBuf::from("."));
|
||||
@@ -33,7 +31,7 @@ pub fn abrir_banco_no_caminho(caminho: &Path) -> Result<(Connection, bool), Stri
|
||||
// Testar se o banco funciona com uma query simples
|
||||
match conn.execute_batch("SELECT 1;") {
|
||||
Ok(_) => return Ok((conn, false)),
|
||||
Err(e) => {
|
||||
Err(_e) => {
|
||||
// Banco corrompido
|
||||
drop(conn);
|
||||
let bak = caminho.with_extension("db.bak");
|
||||
|
||||
@@ -145,55 +145,6 @@ pub fn listar(conn: &Connection) -> Result<Vec<Layout>> {
|
||||
layouts
|
||||
}
|
||||
|
||||
/// Busca um layout pelo id.
|
||||
pub fn buscar_por_id(conn: &Connection, id: i64) -> Result<Option<Layout>> {
|
||||
let mut stmt = conn.prepare(
|
||||
"SELECT id, nome, tipo,
|
||||
delimitador, encoding, linha_cabecalho,
|
||||
indice_numero, indice_serie, indice_valor, indice_data,
|
||||
aba, pos_numero, pos_serie, pos_valor, pos_data
|
||||
FROM layouts WHERE id = ?1",
|
||||
)?;
|
||||
|
||||
let mut results = stmt.query_map([id], |row| {
|
||||
let id: i64 = row.get(0)?;
|
||||
let nome: String = row.get(1)?;
|
||||
let tipo: String = row.get(2)?;
|
||||
|
||||
if tipo == "csv" {
|
||||
let delim_str: String = row.get(3)?;
|
||||
let delimitador = delim_str.chars().next().unwrap_or(';');
|
||||
Ok(Layout::Csv {
|
||||
id: Some(id),
|
||||
nome,
|
||||
config: LayoutCsv {
|
||||
delimitador,
|
||||
encoding: row.get(4)?,
|
||||
linha_cabecalho: row.get::<_, i64>(5)? as usize,
|
||||
indice_numero: row.get::<_, i64>(6)? as usize,
|
||||
indice_serie: row.get::<_, i64>(7)? as usize,
|
||||
indice_valor: row.get::<_, Option<i64>>(8)?.map(|v| v as usize),
|
||||
indice_data: row.get::<_, Option<i64>>(9)?.map(|v| v as usize),
|
||||
},
|
||||
})
|
||||
} else {
|
||||
Ok(Layout::Xlsx {
|
||||
id: Some(id),
|
||||
nome,
|
||||
config: LayoutXlsx {
|
||||
aba: row.get(10)?,
|
||||
pos_numero: row.get(11)?,
|
||||
pos_serie: row.get(12)?,
|
||||
pos_valor: row.get(13)?,
|
||||
pos_data: row.get(14)?,
|
||||
},
|
||||
})
|
||||
}
|
||||
})?;
|
||||
|
||||
results.next().transpose()
|
||||
}
|
||||
|
||||
/// Remove um layout pelo id.
|
||||
pub fn excluir(conn: &Connection, id: i64) -> Result<()> {
|
||||
conn.execute("DELETE FROM layouts WHERE id = ?1", [id])?;
|
||||
|
||||
@@ -21,12 +21,12 @@ pub fn aplicar_migrations(conn: &Connection) -> Result<()> {
|
||||
)
|
||||
.unwrap_or(0);
|
||||
|
||||
if versao_atual < 1 {
|
||||
if versao_atual < VERSAO_SCHEMA_ATUAL {
|
||||
migration_v1(conn)?;
|
||||
if versao_atual == 0 {
|
||||
conn.execute("INSERT INTO schema_version (versao) VALUES (?1);", [1])?;
|
||||
conn.execute("INSERT INTO schema_version (versao) VALUES (?1);", [VERSAO_SCHEMA_ATUAL])?;
|
||||
} else {
|
||||
conn.execute("UPDATE schema_version SET versao = ?1;", [1])?;
|
||||
conn.execute("UPDATE schema_version SET versao = ?1;", [VERSAO_SCHEMA_ATUAL])?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ pub fn ler_xlsx(
|
||||
.worksheet_range(nome_aba)
|
||||
.map_err(|e| ErroArquivo::Corrompido(e.to_string()))?;
|
||||
|
||||
let mut avisos = ResumoAvisos::default();
|
||||
let avisos = ResumoAvisos::default();
|
||||
let mut linhas: Vec<Vec<String>> = Vec::new();
|
||||
|
||||
let linha_inicio_base0 = (linha_inicio.saturating_sub(1)) as usize;
|
||||
|
||||
Reference in New Issue
Block a user