Соцсети: добавлена кнопка-ссылка на сайт infocyber.pro
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+12
-4
@@ -338,12 +338,20 @@ class DatabaseManager:
|
||||
)
|
||||
conn.commit()
|
||||
|
||||
def count_web_registrations(self) -> int:
|
||||
"""Количество заявок с сайта (для генерации следующего ID независимо от Excel)."""
|
||||
def next_web_registration_id(self) -> str:
|
||||
"""Следующий ID веб-заявки вида id_004 по МАКСИМАЛЬНОМУ существующему номеру.
|
||||
|
||||
Считаем по max(числовой суффикс), а не по COUNT: при удалении записей
|
||||
COUNT+1 может совпасть с существующим id и нарушить PRIMARY KEY.
|
||||
"""
|
||||
with self._get_connection() as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute("SELECT COUNT(*) FROM web_registrations")
|
||||
return cursor.fetchone()[0]
|
||||
# substr(id, 4) отрезает префикс 'id_' и приводит к числу
|
||||
cursor.execute(
|
||||
"SELECT COALESCE(MAX(CAST(substr(id, 4) AS INTEGER)), 0) FROM web_registrations "
|
||||
"WHERE id LIKE 'id\\_%' ESCAPE '\\'"
|
||||
)
|
||||
return f"id_{cursor.fetchone()[0] + 1:03d}"
|
||||
|
||||
def add_lead(self, user_id: int, source: str, name: str, phone: str,
|
||||
service: Optional[str] = None, call_time: Optional[str] = None,
|
||||
|
||||
Reference in New Issue
Block a user