att
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user