130 lines
6.0 KiB
Python
130 lines
6.0 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
"""
|
|||
|
|
Проверка статуса жалобы в базе данных
|
|||
|
|
"""
|
|||
|
|
import asyncio
|
|||
|
|
import asyncpg
|
|||
|
|
import json
|
|||
|
|
|
|||
|
|
# Параметры подключения к БД
|
|||
|
|
POSTGRES_HOST = "147.45.189.234"
|
|||
|
|
POSTGRES_PORT = 5432
|
|||
|
|
POSTGRES_DB = "default_db"
|
|||
|
|
POSTGRES_USER = "gen_user"
|
|||
|
|
POSTGRES_PASSWORD = "2~~9_^kVsU?2\\S"
|
|||
|
|
|
|||
|
|
CLAIM_ID = "bddb6815-8e17-4d54-a721-5e94382942c7"
|
|||
|
|
|
|||
|
|
async def check_claim_status():
|
|||
|
|
"""Проверяет статус жалобы"""
|
|||
|
|
conn = None
|
|||
|
|
try:
|
|||
|
|
conn = await asyncpg.connect(
|
|||
|
|
host=POSTGRES_HOST,
|
|||
|
|
port=POSTGRES_PORT,
|
|||
|
|
database=POSTGRES_DB,
|
|||
|
|
user=POSTGRES_USER,
|
|||
|
|
password=POSTGRES_PASSWORD
|
|||
|
|
)
|
|||
|
|
|
|||
|
|
# Запрос статуса жалобы
|
|||
|
|
query = """
|
|||
|
|
SELECT
|
|||
|
|
id,
|
|||
|
|
status_code,
|
|||
|
|
payload->>'claim_id' as claim_id,
|
|||
|
|
payload->>'current_doc_index' as current_doc_index,
|
|||
|
|
jsonb_array_length(COALESCE(payload->'documents_required', '[]'::jsonb)) as documents_required_count,
|
|||
|
|
jsonb_array_length(COALESCE(payload->'documents_uploaded', '[]'::jsonb)) as documents_uploaded_count,
|
|||
|
|
jsonb_array_length(COALESCE(payload->'documents_skipped', '[]'::jsonb)) as documents_skipped_count,
|
|||
|
|
payload->'documents_required' as documents_required,
|
|||
|
|
payload->'documents_uploaded' as documents_uploaded,
|
|||
|
|
payload->'documents_skipped' as documents_skipped,
|
|||
|
|
created_at,
|
|||
|
|
updated_at
|
|||
|
|
FROM clpr_claims
|
|||
|
|
WHERE id::text = $1
|
|||
|
|
OR payload->>'claim_id' = $1
|
|||
|
|
ORDER BY updated_at DESC
|
|||
|
|
LIMIT 1
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
row = await conn.fetchrow(query, CLAIM_ID)
|
|||
|
|
|
|||
|
|
if not row:
|
|||
|
|
print(f"❌ Жалоба с claim_id '{CLAIM_ID}' не найдена")
|
|||
|
|
return
|
|||
|
|
|
|||
|
|
print("=" * 80)
|
|||
|
|
print(f"📋 Статус жалобы: {CLAIM_ID}")
|
|||
|
|
print("=" * 80)
|
|||
|
|
print(f"ID в БД: {row['id']}")
|
|||
|
|
print(f"Status Code: {row['status_code']}")
|
|||
|
|
print(f"Claim ID: {row['claim_id']}")
|
|||
|
|
print(f"Current Doc Index: {row['current_doc_index']}")
|
|||
|
|
print(f"\n📊 Статистика документов:")
|
|||
|
|
print(f" - Требуется документов: {row['documents_required_count']}")
|
|||
|
|
print(f" - Загружено документов: {row['documents_uploaded_count']}")
|
|||
|
|
print(f" - Пропущено документов: {row['documents_skipped_count']}")
|
|||
|
|
print(f"\n📅 Даты:")
|
|||
|
|
print(f" - Создано: {row['created_at']}")
|
|||
|
|
print(f" - Обновлено: {row['updated_at']}")
|
|||
|
|
|
|||
|
|
documents_required = row['documents_required'] if isinstance(row['documents_required'], list) else (json.loads(row['documents_required']) if isinstance(row['documents_required'], str) else [])
|
|||
|
|
documents_uploaded = row['documents_uploaded'] if isinstance(row['documents_uploaded'], list) else (json.loads(row['documents_uploaded']) if isinstance(row['documents_uploaded'], str) else [])
|
|||
|
|
documents_skipped = row['documents_skipped'] if isinstance(row['documents_skipped'], list) else (json.loads(row['documents_skipped']) if isinstance(row['documents_skipped'], str) else [])
|
|||
|
|
|
|||
|
|
if documents_required:
|
|||
|
|
print(f"\n📄 Требуемые документы:")
|
|||
|
|
for idx, doc in enumerate(documents_required):
|
|||
|
|
doc_obj = doc if isinstance(doc, dict) else json.loads(doc) if isinstance(doc, str) else {}
|
|||
|
|
print(f" {idx}. {doc_obj.get('name', doc_obj.get('id', 'unknown'))} (id: {doc_obj.get('id', 'unknown')})")
|
|||
|
|
|
|||
|
|
if documents_uploaded:
|
|||
|
|
print(f"\n✅ Загруженные документы:")
|
|||
|
|
for doc in documents_uploaded:
|
|||
|
|
doc_obj = doc if isinstance(doc, dict) else json.loads(doc) if isinstance(doc, str) else {}
|
|||
|
|
print(f" - {doc_obj.get('id', 'unknown')}: {doc_obj.get('file_name', 'N/A')}")
|
|||
|
|
|
|||
|
|
if documents_skipped:
|
|||
|
|
print(f"\n⏭️ Пропущенные документы:")
|
|||
|
|
for doc in documents_skipped:
|
|||
|
|
doc_obj = doc if isinstance(doc, dict) else json.loads(doc) if isinstance(doc, str) else {}
|
|||
|
|
group_idx = doc_obj.get('group_index', 'N/A')
|
|||
|
|
print(f" - {doc_obj.get('id', 'unknown')} (group_index: {group_idx}): {doc_obj.get('name', 'N/A')}")
|
|||
|
|
|
|||
|
|
print("\n" + "=" * 80)
|
|||
|
|
|
|||
|
|
# Определяем, что должно происходить дальше
|
|||
|
|
status = row['status_code']
|
|||
|
|
uploaded = row['documents_uploaded_count'] or 0
|
|||
|
|
skipped = row['documents_skipped_count'] or 0
|
|||
|
|
required = row['documents_required_count'] or 0
|
|||
|
|
|
|||
|
|
print(f"\n🔍 Анализ статуса:")
|
|||
|
|
if status == 'draft_docs_complete':
|
|||
|
|
print(" ✅ Все документы обработаны (загружены или пропущены)")
|
|||
|
|
print(" 📝 Должно происходить: формирование заявления (wizard generation)")
|
|||
|
|
elif status == 'draft_docs_progress':
|
|||
|
|
print(" ⏳ Документы загружаются")
|
|||
|
|
remaining = required - uploaded - skipped
|
|||
|
|
print(f" 📊 Осталось обработать: {remaining} документов")
|
|||
|
|
elif status == 'draft_new':
|
|||
|
|
print(" 🆕 Новая жалоба, только описание")
|
|||
|
|
elif status == 'draft_claim_ready':
|
|||
|
|
print(" ✅ Заявление готово к отправке")
|
|||
|
|
else:
|
|||
|
|
print(f" ⚠️ Неизвестный статус: {status}")
|
|||
|
|
|
|||
|
|
except Exception as e:
|
|||
|
|
print(f"❌ Ошибка: {e}")
|
|||
|
|
import traceback
|
|||
|
|
traceback.print_exc()
|
|||
|
|
finally:
|
|||
|
|
if conn:
|
|||
|
|
await conn.close()
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
asyncio.run(check_claim_status())
|
|||
|
|
|