feat(Charts): Montado as consultas sqls para popular os gráficos
This commit is contained in:
parent
59f462c7bd
commit
50aa6640a8
18 changed files with 546 additions and 0 deletions
|
|
@ -0,0 +1,26 @@
|
|||
from abstracts.action import BaseAction
|
||||
from api.packages.v1.administrativo.repositories.t_pessoa.t_pessoa_delete_repository import TPessoaDeleteRepository
|
||||
from api.packages.v1.administrativo.schemas.t_pessoa_schema import TPessoaIdSchema
|
||||
|
||||
|
||||
class TPessoaDeleteAction(BaseAction):
|
||||
"""
|
||||
Serviço responsável por encapsular a lógica de negócio para a operação
|
||||
de exclusão de um registro na tabela g_tb_regimebens.
|
||||
"""
|
||||
|
||||
def execute(self, t_pessoa_id_schema: TPessoaIdSchema):
|
||||
"""
|
||||
Executa a operação de exclusão no banco de dados.
|
||||
|
||||
Args:
|
||||
regimebens_schema (GTbRegimebensIdSchema): O esquema com o ID a ser excluído.
|
||||
|
||||
Returns:
|
||||
O resultado da operação de exclusão.
|
||||
"""
|
||||
# Instanciamento do repositório
|
||||
t_pessoa_delete_repository = TPessoaDeleteRepository()
|
||||
|
||||
# Execução do repositório
|
||||
return t_pessoa_delete_repository.execute(t_pessoa_id_schema)
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
from abstracts.repository import BaseRepository
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
class TPessoaChartsCidades(BaseRepository):
|
||||
|
||||
def execute(self):
|
||||
|
||||
try:
|
||||
# Montagem do sql
|
||||
sql = """
|
||||
SELECT FIRST 10 CIDADE, COUNT(*) AS TOTAL
|
||||
FROM T_PESSOA
|
||||
WHERE CIDADE IS NOT NULL
|
||||
GROUP BY CIDADE
|
||||
ORDER BY TOTAL DESC;
|
||||
"""
|
||||
|
||||
# Execução do sql
|
||||
response = self.run(sql)
|
||||
|
||||
# Retorna o resultado
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Informa que houve uma falha na exclusão
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail=f"Erro ao excluir regime de bens: {e}",
|
||||
)
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
from abstracts.repository import BaseRepository
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
class TPessoaChartsCPFSInvalidos(BaseRepository):
|
||||
|
||||
def execute(self):
|
||||
|
||||
try:
|
||||
# Montagem do sql
|
||||
sql = """
|
||||
SELECT PESSOA_ID, NOME, CPF_CNPJ
|
||||
FROM T_PESSOA
|
||||
WHERE CPF_CNPJ IS NULL OR CHAR_LENGTH(CPF_CNPJ) NOT IN (11,14);
|
||||
"""
|
||||
|
||||
# Execução do sql
|
||||
response = self.run(sql)
|
||||
|
||||
# Retorna o resultado
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Informa que houve uma falha na exclusão
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail=f"Erro ao excluir regime de bens: {e}",
|
||||
)
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
from abstracts.repository import BaseRepository
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
class TPessoaChartsCPFSPReenchidos(BaseRepository):
|
||||
|
||||
def execute(self):
|
||||
|
||||
try:
|
||||
# Montagem do sql
|
||||
sql = """
|
||||
SELECT
|
||||
COUNT(*) AS TOTAL_VALIDO,
|
||||
(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM T_PESSOA)) AS PERCENTUAL
|
||||
FROM T_PESSOA
|
||||
WHERE CPF_CNPJ IS NOT NULL
|
||||
AND (CHAR_LENGTH(CPF_CNPJ) = 11 OR CHAR_LENGTH(CPF_CNPJ) = 14);
|
||||
"""
|
||||
|
||||
# Execução do sql
|
||||
response = self.run(sql)
|
||||
|
||||
# Retorna o resultado
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Informa que houve uma falha na exclusão
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail=f"Erro ao excluir regime de bens: {e}",
|
||||
)
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
from abstracts.repository import BaseRepository
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
class TPessoaChartsDocumentosValidos(BaseRepository):
|
||||
|
||||
def execute(self):
|
||||
|
||||
try:
|
||||
# Montagem do sql
|
||||
sql = """
|
||||
SELECT
|
||||
COUNT(*) AS TOTAL_DOCUMENTOS_VALIDOS,
|
||||
(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM T_PESSOA)) AS PERCENTUAL
|
||||
FROM T_PESSOA
|
||||
WHERE DOCUMENTO_VALIDADE > CURRENT_DATE;
|
||||
"""
|
||||
|
||||
# Execução do sql
|
||||
response = self.run(sql)
|
||||
|
||||
# Retorna o resultado
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Informa que houve uma falha na exclusão
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail=f"Erro ao excluir regime de bens: {e}",
|
||||
)
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
from abstracts.repository import BaseRepository
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
class TPessoaChartsEmailPreenchido(BaseRepository):
|
||||
|
||||
def execute(self):
|
||||
|
||||
try:
|
||||
# Montagem do sql
|
||||
sql = """
|
||||
SELECT
|
||||
COUNT(*) AS TOTAL_EMAIL,
|
||||
(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM T_PESSOA)) AS PERCENTUAL
|
||||
FROM T_PESSOA
|
||||
WHERE EMAIL IS NOT NULL AND EMAIL LIKE '%@%';
|
||||
"""
|
||||
|
||||
# Execução do sql
|
||||
response = self.run(sql)
|
||||
|
||||
# Retorna o resultado
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Informa que houve uma falha na exclusão
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail=f"Erro ao excluir regime de bens: {e}",
|
||||
)
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
from abstracts.repository import BaseRepository
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
class TPessoaChartsEnderecoCompleto(BaseRepository):
|
||||
|
||||
def execute(self):
|
||||
|
||||
try:
|
||||
# Montagem do sql
|
||||
sql = """
|
||||
SELECT
|
||||
COUNT(*) AS TOTAL_ENDERECO,
|
||||
(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM T_PESSOA)) AS PERCENTUAL
|
||||
FROM T_PESSOA
|
||||
WHERE ENDERECO IS NOT NULL AND CIDADE IS NOT NULL AND UF IS NOT NULL;
|
||||
"""
|
||||
|
||||
# Execução do sql
|
||||
response = self.run(sql)
|
||||
|
||||
# Retorna o resultado
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Informa que houve uma falha na exclusão
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail=f"Erro ao excluir regime de bens: {e}",
|
||||
)
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
from abstracts.repository import BaseRepository
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
class TPessoaChartsEstadoCivil(BaseRepository):
|
||||
|
||||
def execute(self):
|
||||
|
||||
try:
|
||||
# Montagem do sql
|
||||
sql = """
|
||||
SELECT
|
||||
G.DESCRICAO AS ESTADO_CIVIL,
|
||||
COUNT(P.PESSOA_ID) AS TOTAL
|
||||
FROM T_PESSOA P
|
||||
LEFT JOIN G_TB_ESTADOCIVIL G ON G.TB_ESTADOCIVIL_ID = P.TB_ESTADOCIVIL_ID
|
||||
GROUP BY G.DESCRICAO
|
||||
ORDER BY TOTAL DESC;
|
||||
"""
|
||||
|
||||
# Execução do sql
|
||||
response = self.run(sql)
|
||||
|
||||
# Retorna o resultado
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Informa que houve uma falha na exclusão
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail=f"Erro ao excluir regime de bens: {e}",
|
||||
)
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
from abstracts.repository import BaseRepository
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
class TPessoaChartsEstrangeiros(BaseRepository):
|
||||
|
||||
def execute(self):
|
||||
|
||||
try:
|
||||
# Montagem do sql
|
||||
sql = """
|
||||
SELECT
|
||||
COUNT(*) AS TOTAL_ESTRANGEIROS,
|
||||
(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM T_PESSOA)) AS PERCENTUAL
|
||||
FROM T_PESSOA
|
||||
WHERE ESTRANGEIRO_NAT = 'S' OR ESTRANGEIRO_RES = 'S';
|
||||
"""
|
||||
|
||||
# Execução do sql
|
||||
response = self.run(sql)
|
||||
|
||||
# Retorna o resultado
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Informa que houve uma falha na exclusão
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail=f"Erro ao excluir regime de bens: {e}",
|
||||
)
|
||||
|
|
@ -0,0 +1,38 @@
|
|||
from abstracts.repository import BaseRepository
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
class TPEssoaChartsFaixaEtaria(BaseRepository):
|
||||
|
||||
def execute(self):
|
||||
|
||||
try:
|
||||
# Montagem do sql
|
||||
sql = """
|
||||
SELECT
|
||||
CASE
|
||||
WHEN (EXTRACT(YEAR FROM CURRENT_DATE) - EXTRACT(YEAR FROM DATA_NASCIMENTO)) < 18 THEN 'Menores de 18'
|
||||
WHEN (EXTRACT(YEAR FROM CURRENT_DATE) - EXTRACT(YEAR FROM DATA_NASCIMENTO)) BETWEEN 18 AND 30 THEN '18-30'
|
||||
WHEN (EXTRACT(YEAR FROM CURRENT_DATE) - EXTRACT(YEAR FROM DATA_NASCIMENTO)) BETWEEN 31 AND 45 THEN '31-45'
|
||||
WHEN (EXTRACT(YEAR FROM CURRENT_DATE) - EXTRACT(YEAR FROM DATA_NASCIMENTO)) BETWEEN 46 AND 60 THEN '46-60'
|
||||
ELSE 'Acima de 60'
|
||||
END AS FAIXA_ETARIA,
|
||||
COUNT(*) AS TOTAL
|
||||
FROM T_PESSOA
|
||||
WHERE DATA_NASCIMENTO IS NOT NULL
|
||||
GROUP BY 1
|
||||
ORDER BY TOTAL DESC;
|
||||
"""
|
||||
|
||||
# Execução do sql
|
||||
response = self.run(sql)
|
||||
|
||||
# Retorna o resultado
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Informa que houve uma falha na exclusão
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail=f"Erro ao excluir regime de bens: {e}",
|
||||
)
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
from abstracts.repository import BaseRepository
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
class TPessoaChartsLinhaTempo(BaseRepository):
|
||||
|
||||
def execute(self):
|
||||
|
||||
try:
|
||||
# Montagem do sql
|
||||
sql = """
|
||||
SELECT
|
||||
EXTRACT(YEAR FROM DATA_CADASTRO) AS ANO,
|
||||
EXTRACT(MONTH FROM DATA_CADASTRO) AS MES,
|
||||
COUNT(*) AS TOTAL
|
||||
FROM T_PESSOA
|
||||
WHERE DATA_CADASTRO IS NOT NULL
|
||||
GROUP BY EXTRACT(YEAR FROM DATA_CADASTRO), EXTRACT(MONTH FROM DATA_CADASTRO)
|
||||
ORDER BY ANO, MES;
|
||||
"""
|
||||
|
||||
# Execução do sql
|
||||
response = self.run(sql)
|
||||
|
||||
# Retorna o resultado
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Informa que houve uma falha na exclusão
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail=f"Erro ao excluir regime de bens: {e}",
|
||||
)
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
from abstracts.repository import BaseRepository
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
class TPessoaDeleteRepository(BaseRepository):
|
||||
|
||||
def execute(self):
|
||||
|
||||
try:
|
||||
# Montagem do sql
|
||||
sql = """
|
||||
SELECT
|
||||
AVG(EXTRACT(YEAR FROM CURRENT_DATE) - EXTRACT(YEAR FROM DATA_NASCIMENTO)) AS MEDIA_IDADE
|
||||
FROM T_PESSOA
|
||||
WHERE DATA_NASCIMENTO IS NOT NULL;
|
||||
"""
|
||||
|
||||
# Execução do sql
|
||||
response = self.run(sql)
|
||||
|
||||
# Retorna o resultado
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Informa que houve uma falha na exclusão
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail=f"Erro ao excluir regime de bens: {e}",
|
||||
)
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
from abstracts.repository import BaseRepository
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
class TPessoaChartsNovosCadastros(BaseRepository):
|
||||
|
||||
def execute(self):
|
||||
|
||||
try:
|
||||
# Montagem do sql
|
||||
sql = """
|
||||
SELECT COUNT(*) AS NOVOS_MES
|
||||
FROM T_PESSOA
|
||||
WHERE EXTRACT(MONTH FROM DATA_CADASTRO) = EXTRACT(MONTH FROM CURRENT_DATE)
|
||||
AND EXTRACT(YEAR FROM DATA_CADASTRO) = EXTRACT(YEAR FROM CURRENT_DATE);
|
||||
"""
|
||||
|
||||
# Execução do sql
|
||||
response = self.run(sql)
|
||||
|
||||
# Retorna o resultado
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Informa que houve uma falha na exclusão
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail=f"Erro ao excluir regime de bens: {e}",
|
||||
)
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
from abstracts.repository import BaseRepository
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
class TPessoaChartsProfissoes(BaseRepository):
|
||||
|
||||
def execute(self):
|
||||
|
||||
try:
|
||||
# Montagem do sql
|
||||
sql = """
|
||||
SELECT
|
||||
G.DESCRICAO AS PROFISSAO,
|
||||
COUNT(P.PESSOA_ID) AS TOTAL
|
||||
FROM T_PESSOA P
|
||||
LEFT JOIN G_TB_PROFISSAO G ON G.TB_PROFISSAO_ID = P.TB_PROFISSAO_ID
|
||||
GROUP BY G.DESCRICAO
|
||||
ORDER BY TOTAL DESC;
|
||||
"""
|
||||
|
||||
# Execução do sql
|
||||
response = self.run(sql)
|
||||
|
||||
# Retorna o resultado
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Informa que houve uma falha na exclusão
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail=f"Erro ao excluir regime de bens: {e}",
|
||||
)
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
from abstracts.repository import BaseRepository
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
class TPessoaChartsSexo(BaseRepository):
|
||||
|
||||
def execute(self):
|
||||
|
||||
try:
|
||||
# Montagem do sql
|
||||
sql = """
|
||||
SELECT
|
||||
CASE
|
||||
WHEN SEXO = 'M' THEN 'Masculino'
|
||||
WHEN SEXO = 'F' THEN 'Feminino'
|
||||
ELSE 'Não Informado'
|
||||
END AS SEXO,
|
||||
COUNT(*) AS TOTAL
|
||||
FROM T_PESSOA
|
||||
GROUP BY 1
|
||||
ORDER BY TOTAL DESC;
|
||||
"""
|
||||
|
||||
# Execução do sql
|
||||
response = self.run(sql)
|
||||
|
||||
# Retorna o resultado
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Informa que houve uma falha na exclusão
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail=f"Erro ao excluir regime de bens: {e}",
|
||||
)
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
from abstracts.repository import BaseRepository
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
class TPessoaChartsTelefoneValido(BaseRepository):
|
||||
|
||||
def execute(self):
|
||||
|
||||
try:
|
||||
# Montagem do sql
|
||||
sql = """
|
||||
SELECT
|
||||
COUNT(*) AS TOTAL_TELEFONE,
|
||||
(COUNT(*) * 100.0 / (SELECT COUNT(*) FROM T_PESSOA)) AS PERCENTUAL
|
||||
FROM T_PESSOA
|
||||
WHERE TELEFONE IS NOT NULL AND CHAR_LENGTH(TELEFONE) >= 8;
|
||||
"""
|
||||
|
||||
# Execução do sql
|
||||
response = self.run(sql)
|
||||
|
||||
# Retorna o resultado
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Informa que houve uma falha na exclusão
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail=f"Erro ao excluir regime de bens: {e}",
|
||||
)
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
from abstracts.repository import BaseRepository
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
class TPessoaCahrtsTotal(BaseRepository):
|
||||
|
||||
def execute(self):
|
||||
|
||||
try:
|
||||
# Montagem do sql
|
||||
sql = """ SELECT COUNT(*) AS TOTAL_PESSOAS FROM T_PESSOA; """
|
||||
|
||||
# Execução do sql
|
||||
response = self.run(sql)
|
||||
|
||||
# Retorna o resultado
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Informa que houve uma falha na exclusão
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail=f"Erro ao excluir regime de bens: {e}",
|
||||
)
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
from abstracts.repository import BaseRepository
|
||||
from fastapi import HTTPException, status
|
||||
|
||||
|
||||
class TPessoasChartsUf(BaseRepository):
|
||||
|
||||
def execute(self):
|
||||
|
||||
try:
|
||||
# Montagem do sql
|
||||
sql = """
|
||||
SELECT UF, COUNT(*) AS TOTAL
|
||||
FROM T_PESSOA
|
||||
GROUP BY UF
|
||||
ORDER BY TOTAL DESC;
|
||||
"""
|
||||
|
||||
# Execução do sql
|
||||
response = self.run(sql)
|
||||
|
||||
# Retorna o resultado
|
||||
return response
|
||||
|
||||
except Exception as e:
|
||||
# Informa que houve uma falha na exclusão
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
detail=f"Erro ao excluir regime de bens: {e}",
|
||||
)
|
||||
Loading…
Add table
Reference in a new issue