feat: Получение cf_2624 из MySQL и блокировка полей при подтверждении данных
- Добавлен сервис CrmMySQLService для прямого подключения к MySQL CRM - Обновлён метод get_draft() для получения cf_2624 напрямую из БД - Реализована блокировка полей (readonly) при contact_data_confirmed = true - Добавлен выбор банка для СБП выплат с динамической загрузкой из API - Обновлена документация по работе с cf_2624 и MySQL - Добавлен network_mode: host в docker-compose для доступа к MySQL - Обновлены компоненты формы для поддержки блокировки полей
This commit is contained in:
72
docs/migrations/002_add_document_match.sql
Normal file
72
docs/migrations/002_add_document_match.sql
Normal file
@@ -0,0 +1,72 @@
|
||||
-- ============================================================================
|
||||
-- Миграция 002: Добавление проверки соответствия документов
|
||||
-- ============================================================================
|
||||
-- Цель: Хранить результат проверки AI — соответствует ли загруженный документ
|
||||
-- запрошенному типу (договор, чек, переписка и т.д.)
|
||||
-- ============================================================================
|
||||
|
||||
-- Добавляем колонки в clpr_claim_documents
|
||||
ALTER TABLE clpr_claim_documents
|
||||
ADD COLUMN IF NOT EXISTS document_type VARCHAR(50), -- ожидаемый тип: contract, payment, correspondence, evidence_photo
|
||||
ADD COLUMN IF NOT EXISTS document_label VARCHAR(255), -- читаемое название: "Договор или заказ"
|
||||
ADD COLUMN IF NOT EXISTS match_score INT, -- процент соответствия 0-100
|
||||
ADD COLUMN IF NOT EXISTS match_status VARCHAR(20) DEFAULT 'pending', -- pending/passed/failed/skipped
|
||||
ADD COLUMN IF NOT EXISTS match_reason TEXT, -- пояснение от AI почему такой score
|
||||
ADD COLUMN IF NOT EXISTS match_checked_at TIMESTAMP; -- когда проверено
|
||||
|
||||
-- Комментарии к колонкам
|
||||
COMMENT ON COLUMN clpr_claim_documents.document_type IS 'Ожидаемый тип документа: contract, payment, correspondence, evidence_photo, other';
|
||||
COMMENT ON COLUMN clpr_claim_documents.document_label IS 'Читаемое название типа документа: "Договор или заказ", "Чек", "Переписка"';
|
||||
COMMENT ON COLUMN clpr_claim_documents.match_score IS 'Процент соответствия документа ожидаемому типу (0-100). NULL = не проверено';
|
||||
COMMENT ON COLUMN clpr_claim_documents.match_status IS 'Статус проверки: pending (ждёт), passed (ок), failed (не соответствует), skipped (пропущено)';
|
||||
COMMENT ON COLUMN clpr_claim_documents.match_reason IS 'Пояснение от AI: почему документ соответствует/не соответствует';
|
||||
COMMENT ON COLUMN clpr_claim_documents.match_checked_at IS 'Когда была выполнена проверка соответствия';
|
||||
|
||||
-- Индекс для быстрого поиска непроверенных и проблемных документов
|
||||
CREATE INDEX IF NOT EXISTS idx_claim_docs_match_status
|
||||
ON clpr_claim_documents(claim_id, match_status);
|
||||
|
||||
-- Заполняем document_type и document_label из payload для существующих документов
|
||||
UPDATE clpr_claim_documents cd
|
||||
SET
|
||||
document_type = du.doc_type,
|
||||
document_label = dm.field_label
|
||||
FROM clpr_claims c,
|
||||
LATERAL (
|
||||
SELECT x->>'field_label' AS field_label
|
||||
FROM jsonb_array_elements(COALESCE(c.payload->'documents_meta', '[]'::jsonb)) x
|
||||
WHERE x->>'field_name' = cd.field_name
|
||||
LIMIT 1
|
||||
) dm,
|
||||
LATERAL (
|
||||
SELECT x->>'type' AS doc_type
|
||||
FROM jsonb_array_elements(COALESCE(c.payload->'documents_uploaded', '[]'::jsonb)) x
|
||||
WHERE x->>'file_name' = cd.file_name OR x->>'file_id' LIKE '%' || cd.file_name
|
||||
LIMIT 1
|
||||
) du
|
||||
WHERE cd.claim_id::text = c.id::text
|
||||
AND cd.document_type IS NULL;
|
||||
|
||||
-- Статистика после миграции
|
||||
DO $$
|
||||
DECLARE
|
||||
total_docs INT;
|
||||
with_type INT;
|
||||
with_label INT;
|
||||
BEGIN
|
||||
SELECT COUNT(*) INTO total_docs FROM clpr_claim_documents;
|
||||
SELECT COUNT(*) INTO with_type FROM clpr_claim_documents WHERE document_type IS NOT NULL;
|
||||
SELECT COUNT(*) INTO with_label FROM clpr_claim_documents WHERE document_label IS NOT NULL;
|
||||
|
||||
RAISE NOTICE '=== Document Match Migration Complete ===';
|
||||
RAISE NOTICE 'Total documents: %', total_docs;
|
||||
RAISE NOTICE 'With document_type: %', with_type;
|
||||
RAISE NOTICE 'With document_label: %', with_label;
|
||||
END $$;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user