Update app.py
Browse files
app.py
CHANGED
|
@@ -554,7 +554,8 @@ else:
|
|
| 554 |
if turma_selecionada != "Todas":
|
| 555 |
# Usamos LIKE porque a coluna é TEXT e pode conter múltiplas turmas
|
| 556 |
filtro_sql += f" AND turmas LIKE '%%{turma_selecionada}%%'"
|
| 557 |
-
|
|
|
|
| 558 |
query_sem_acesso = f"""
|
| 559 |
SELECT nome, sobrenome, email, celular, nome_curso, turmas, ultimo_acesso
|
| 560 |
FROM portal_alunos_flat
|
|
@@ -565,12 +566,21 @@ else:
|
|
| 565 |
ultimo_acesso IS NULL
|
| 566 |
OR ultimo_acesso = ''
|
| 567 |
OR ultimo_acesso = '0000-00-00 00:00:00'
|
| 568 |
-
OR
|
| 569 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 570 |
)
|
| 571 |
ORDER BY nome_curso ASC, turmas ASC, nome ASC
|
| 572 |
"""
|
| 573 |
-
|
| 574 |
df_sem_acesso = pd.read_sql(query_sem_acesso, conn)
|
| 575 |
|
| 576 |
if not df_sem_acesso.empty:
|
|
|
|
| 554 |
if turma_selecionada != "Todas":
|
| 555 |
# Usamos LIKE porque a coluna é TEXT e pode conter múltiplas turmas
|
| 556 |
filtro_sql += f" AND turmas LIKE '%%{turma_selecionada}%%'"
|
| 557 |
+
|
| 558 |
+
# Query Principal Corrigida com NULLIF e verificação de string válida
|
| 559 |
query_sem_acesso = f"""
|
| 560 |
SELECT nome, sobrenome, email, celular, nome_curso, turmas, ultimo_acesso
|
| 561 |
FROM portal_alunos_flat
|
|
|
|
| 566 |
ultimo_acesso IS NULL
|
| 567 |
OR ultimo_acesso = ''
|
| 568 |
OR ultimo_acesso = '0000-00-00 00:00:00'
|
| 569 |
+
OR TRIM(ultimo_acesso) = ''
|
| 570 |
+
-- Converte para data com segurança usando CASE/WHEN para ignorar strings vazias
|
| 571 |
+
OR (
|
| 572 |
+
ultimo_acesso LIKE '%%/%%/%%'
|
| 573 |
+
AND STR_TO_DATE(NULLIF(ultimo_acesso, ''), '%%d/%%m/%%Y') < '{hoje.year}-01-01'
|
| 574 |
+
)
|
| 575 |
+
-- Se contiver texto sem o ano atual
|
| 576 |
+
OR (
|
| 577 |
+
ultimo_acesso NOT LIKE '%%{hoje.year}%%'
|
| 578 |
+
AND ultimo_acesso NOT LIKE '%%/%%/%%'
|
| 579 |
+
)
|
| 580 |
)
|
| 581 |
ORDER BY nome_curso ASC, turmas ASC, nome ASC
|
| 582 |
"""
|
| 583 |
+
|
| 584 |
df_sem_acesso = pd.read_sql(query_sem_acesso, conn)
|
| 585 |
|
| 586 |
if not df_sem_acesso.empty:
|