From 001e7a19aae174a29740c1bf477efe1ca99e7f9f Mon Sep 17 00:00:00 2001 From: Sidney Date: Fri, 8 May 2026 11:42:20 -0300 Subject: [PATCH] =?UTF-8?q?docs:=20oficializada=20intelig=C3=AAncia=20de?= =?UTF-8?q?=20disparos=20e=20sincroniza=C3=A7=C3=A3o=20reversa=20no=20GEMI?= =?UTF-8?q?NI=20e=20MEMORY?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- GEMINI.md | 1 + MEMORY.md | 12 +++++------- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/GEMINI.md b/GEMINI.md index 7a48aa9..7e40179 100644 --- a/GEMINI.md +++ b/GEMINI.md @@ -59,3 +59,4 @@ 30. **Financial Data Integrity**: Automation routines MUST prioritize `school_data.payments` (JSON) as the trigger source while using `alunos_cobrancas` (SQL) for tracking notification counters (spam control), ensuring 100% parity with the management UI. 31. **Real-Time Bidirectional Sync**: Asaas webhooks MUST update both the PostgreSQL `alunos_cobrancas` table and the legacy `school_data.json` file in real-time to ensure immediate UI feedback in the administrative panel. 32. **Numerical Type Enforcement**: When serving data from PostgreSQL `NUMERIC` columns, the backend MUST map the result to ensure amounts are sent as `Number` (not String) to prevent string concatenation bugs in the frontend. +33. **Reverse Sync Requirement (SQL -> JSON)**: To ensure visual consistency and avoid automation errors (like double billing), the system MUST perform a reverse sync from `alunos_cobrancas` (SQL) to `school_data.payments` (JSON) during server initialization and on-demand via the `/api/admin/sync-finance-json` endpoint. diff --git a/MEMORY.md b/MEMORY.md index 946ef84..282dd54 100644 --- a/MEMORY.md +++ b/MEMORY.md @@ -107,13 +107,11 @@ - **Melhoria:** O build agora ocorre diretamente na arquitetura de destino, sem emulação QEMU, garantindo velocidade e estabilidade total. ### 📅 08/05/2026 - Estabilização Crítica de Automação e Sincronia Financeira -- 30. **Financial Data Integrity**: Automation routines MUST prioritize `school_data.payments` (JSON) as the trigger source while using `alunos_cobrancas` (SQL) for tracking notification counters (spam control), ensuring 100% parity with the management UI. -- 31. **Real-Time Bidirectional Sync**: Asaas webhooks MUST update both the PostgreSQL `alunos_cobrancas` table and the legacy `school_data.json` file in real-time to ensure immediate UI feedback in the administrative panel. -- 32. **Numerical Type Enforcement**: When serving data from PostgreSQL `NUMERIC` columns, the backend MUST map the result to ensure amounts are sent as `Number` (not String) to prevent string concatenation bugs in the frontend. -- **Sincronização Bidirecional (Webhook):** O webhook do Asaas agora atualiza o SQL **e** o arquivo `school_data.json` em tempo real, garantindo que o status "Pago" apareça instantaneamente no painel. -- **Integridade Numérica:** Resolvido bug de exibição de valores (concatenação de strings) através de casting explícito para `Number()` no backend e frontend. -- **Busca Híbrida de Alunos:** O envio de WhatsApp agora busca o aluno no JSON e faz fallback no SQL. -- **Resiliência de Telefone:** Lógica de "Melhor Esforço" para seleção de telefone (Responsável vs Aluno). +- **Fonte de Disparos:** A rotina de cobranças agora utiliza o `school_data.payments` (JSON) como fonte primária, mas com **Sincronização Reversa** ativa (SQL -> JSON). +- **Sincronização Bidirecional (Webhook):** O webhook do Asaas atualiza o SQL e o JSON em tempo real. +- **Resolução de Fantasmas:** Refinada a lógica de sincronia no Financeiro para atualizar apenas mudanças de status reais, eliminando o aviso persistente de "96 atualizações". +- **Inteligência de Mensagens:** O sistema agora garante que lembretes preventivos NUNCA sejam enviados para boletos já pagos no SQL/JSON. +- **Integridade Numérica:** Casting explícito para `Number()` em todo o fluxo financeiro. ### 📢 Automação de Mensagens - [x] **Estabilização de Lembretes (V2):** Resolvido bug de deslocamento de fuso horário (-1 dia) nas datas de vencimento. Implementadas ferramentas de debug (ignorar trava diária e reset de contadores) e **controle manual de delay para disparos em massa** para facilitar testes e garantir segurança contra banimento.