This commit is contained in:
Cunha 2026-06-23 16:33:53 -03:00
parent cdf5aad1c8
commit a9ddcecdcc
3 changed files with 16 additions and 5 deletions

View File

@ -376,11 +376,22 @@ WHERE TABLE_SCHEMA='dbo' AND TABLE_NAME='Grgb_vendas_report'
return safe_cols
def _is_already_imported(cur, file_name: str) -> bool:
def _is_already_imported(cur, file_name: str, start_date: str = "", end_date: str = "") -> bool:
cur.execute(
"SELECT 1 FROM dbo.Grgb_vendas_import_log WHERE FileName = ?", file_name
)
return cur.fetchone() is not None
if cur.fetchone() is not None:
return True
# bloqueia se o período já está coberto por outro arquivo
if start_date and end_date:
cur.execute(
"SELECT 1 FROM dbo.Grgb_vendas_import_log "
"WHERE PeriodoInicio <= ? AND PeriodoFim >= ?",
end_date, start_date,
)
if cur.fetchone() is not None:
return True
return False
def _import_csv(
@ -402,8 +413,8 @@ def _import_csv(
safe_cols = _ensure_tables(cur, csv_cols)
cn.commit()
if _is_already_imported(cur, file_name):
print(f"[skip] {file_name} ja importado anteriormente")
if _is_already_imported(cur, file_name, start_date, end_date):
print(f"[skip] {file_name} periodo {start_date}..{end_date} ja importado anteriormente")
cur.close(); cn.close()
return 0

View File

@ -1 +1 @@
{"last_end_date": "2026-05-24"}
{"last_end_date": "2026-06-22"}