удалени лишнего после аварии, работа за рабочий день 07.08.2026
This commit is contained in:
+51
-2
@@ -98,7 +98,6 @@ def init_db():
|
||||
|
||||
sync_knowledge_base_to_db()
|
||||
|
||||
|
||||
def has_scud_logs_for_date(date_str):
|
||||
"""Проверяет, есть ли в базе данные СКУД за указанную дату."""
|
||||
with get_connection() as conn:
|
||||
@@ -106,6 +105,16 @@ def has_scud_logs_for_date(date_str):
|
||||
cursor.execute("SELECT 1 FROM scud_logs WHERE log_date = ? LIMIT 1", (date_str,))
|
||||
return cursor.fetchone() is not None
|
||||
|
||||
def has_yesterday_final_snapshot(date_str):
|
||||
"""Проверяет, зафиксирован ли уже ИТОГОВЫЙ вчерашний снапшот с индексом Y/22:00."""
|
||||
with get_connection() as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
"SELECT 1 FROM scud_logs WHERE log_date = ? AND (snapshot_id LIKE 'Y%' OR snapshot_time LIKE '%22:00:00') LIMIT 1",
|
||||
(date_str,)
|
||||
)
|
||||
return cursor.fetchone() is not None
|
||||
|
||||
|
||||
def get_or_create_snapshot_id(snapshot_time, date_str=None, is_yesterday=False):
|
||||
"""
|
||||
@@ -393,4 +402,44 @@ def delete_snapshots_by_date(date_str: str):
|
||||
deleted_count = cursor.rowcount
|
||||
conn.commit()
|
||||
print(f"[✓] Удалены все снапшоты за дату [{date_str}]. Удалено строк: {deleted_count}")
|
||||
return deleted_count
|
||||
return deleted_count
|
||||
def init_department_synonyms_db():
|
||||
"""Создает таблицу синонимов отделов в БД SQLite."""
|
||||
with get_connection() as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("""
|
||||
CREATE TABLE IF NOT EXISTS department_synonyms (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
short_name TEXT UNIQUE NOT NULL,
|
||||
full_name TEXT NOT NULL,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
""")
|
||||
# По умолчанию добавляем ОВК -> Отдел внутреннего контроля
|
||||
cursor.execute("""
|
||||
INSERT OR IGNORE INTO department_synonyms (short_name, full_name)
|
||||
VALUES ('овк', 'отдел внутреннего контроля')
|
||||
""")
|
||||
conn.commit()
|
||||
|
||||
|
||||
def get_department_synonyms_dict():
|
||||
"""Возвращает словарь всех изученных синонимов {short_name: full_name}."""
|
||||
init_department_synonyms_db()
|
||||
with get_connection() as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT LOWER(short_name), LOWER(full_name) FROM department_synonyms")
|
||||
return {row[0]: row[1] for row in cursor.fetchall()}
|
||||
|
||||
|
||||
def add_department_synonym_to_db(short_name, full_name):
|
||||
"""Сохраняет новую пару синонимов отдела в базу SQLite."""
|
||||
init_department_synonyms_db()
|
||||
with get_connection() as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
"INSERT OR REPLACE INTO department_synonyms (short_name, full_name) VALUES (?, ?)",
|
||||
(short_name.strip().lower(), full_name.strip().lower())
|
||||
)
|
||||
conn.commit()
|
||||
print(f"[✓] В базу SQLite добавлен новый синоним отдела: '{short_name}' ⟷ '{full_name}'")
|
||||
|
||||
Reference in New Issue
Block a user