libretificacaotjcore 0.1.37__py3-none-any.whl → 0.1.46__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of libretificacaotjcore might be problematic. Click here for more details.
- libretificacaotjcore/database/config_db.py +15 -0
- libretificacaotjcore/database/rubrica_repository.py +32 -0
- libretificacaotjcore/database/tempo_processo_repository.py +63 -0
- libretificacaotjcore/enums/e_eventos.py +1 -0
- libretificacaotjcore/enums/e_fase_retificacao.py +21 -20
- libretificacaotjcore/services/rabbitmq_consumer.py +35 -32
- {libretificacaotjcore-0.1.37.dist-info → libretificacaotjcore-0.1.46.dist-info}/METADATA +1 -1
- {libretificacaotjcore-0.1.37.dist-info → libretificacaotjcore-0.1.46.dist-info}/RECORD +10 -8
- {libretificacaotjcore-0.1.37.dist-info → libretificacaotjcore-0.1.46.dist-info}/WHEEL +0 -0
- {libretificacaotjcore-0.1.37.dist-info → libretificacaotjcore-0.1.46.dist-info}/top_level.txt +0 -0
|
@@ -35,6 +35,21 @@ class ConfigDb:
|
|
|
35
35
|
await self.__db.protocolos.create_index([("id", 1)], unique=True)
|
|
36
36
|
await self.__db.protocolos.create_index([("solicitacaoId", 1), ("evento", 1)], unique=True)
|
|
37
37
|
self.db_initialized = True
|
|
38
|
+
|
|
39
|
+
if "rubricas" not in (await self.__db.list_collection_names()):
|
|
40
|
+
await self.__db.create_collection("rubricas")
|
|
41
|
+
|
|
42
|
+
await self.__db.rubricas.create_index([("cnpj", 1)])
|
|
43
|
+
await self.__db.rubricas.create_index([("solicitacaoId", 1)], unique=True)
|
|
44
|
+
await self.__db.rubricas.create_index([("id", 1)], unique=True)
|
|
45
|
+
self.db_initialized = True
|
|
46
|
+
|
|
47
|
+
if "tempo_processos" not in (await self.__db.list_collection_names()):
|
|
48
|
+
await self.__db.create_collection("tempo_processos")
|
|
49
|
+
|
|
50
|
+
await self.__db.rubricas.create_index([("solicitacaoId", 1)])
|
|
51
|
+
await self.__db.rubricas.create_index([("id", 1)], unique=True)
|
|
52
|
+
self.db_initialized = True
|
|
38
53
|
|
|
39
54
|
async def get_db(self):
|
|
40
55
|
await self.criar_schema()
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
from pymongo.errors import BulkWriteError
|
|
2
|
+
|
|
3
|
+
class RubricaRepository:
|
|
4
|
+
def __init__(self, db):
|
|
5
|
+
self.__db = db
|
|
6
|
+
|
|
7
|
+
async def inserir_rubrica(self, rubrica: dict) -> bool:
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
rubricas_no_db = await self.__db.rubricas.find_one(
|
|
11
|
+
{"solicitacaoId": rubrica["solicitacaoId"]}
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
if rubricas_no_db is None:
|
|
15
|
+
await self.__db.rubricas.insert_one(rubrica)
|
|
16
|
+
return True
|
|
17
|
+
|
|
18
|
+
await self.__db.rubricas.delete_one(
|
|
19
|
+
{"solicitacaoId": rubrica["solicitacaoId"]}
|
|
20
|
+
)
|
|
21
|
+
await self.__db.rubricas.insert_one(rubrica)
|
|
22
|
+
return True
|
|
23
|
+
except Exception as e:
|
|
24
|
+
print(f"❌ Erro ao inserir o rubrica: {e}")
|
|
25
|
+
return False
|
|
26
|
+
|
|
27
|
+
async def buscar_por_solicitacao_id(self, solicitacaoId: int) -> dict:
|
|
28
|
+
try:
|
|
29
|
+
return await self.__db.rubricas.find_one({"solicitacaoId": solicitacaoId})
|
|
30
|
+
except Exception as e:
|
|
31
|
+
print(f"❌ Erro ao buscar rubricas por solicitacaoId: {e}")
|
|
32
|
+
return {}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from pymongo.errors import BulkWriteError
|
|
3
|
+
|
|
4
|
+
class TempoProcessoRepository:
|
|
5
|
+
def __init__(self, db):
|
|
6
|
+
self.__db = db
|
|
7
|
+
|
|
8
|
+
async def inserir_processo(self, processo: dict) -> bool:
|
|
9
|
+
try:
|
|
10
|
+
processo_no_db = await self.__db.tempo_processos.find_one(
|
|
11
|
+
{"solicitacaoId": processo["solicitacaoId"], "fase": processo["fase"], "data_inicio": processo["data_inicio"], "data_fim": processo["data_fim"]}
|
|
12
|
+
)
|
|
13
|
+
|
|
14
|
+
if processo_no_db is None:
|
|
15
|
+
await self.__db.tempo_processos.insert_one(processo)
|
|
16
|
+
return True
|
|
17
|
+
|
|
18
|
+
await self.__db.tempo_processos.delete_one(
|
|
19
|
+
{"solicitacaoId": processo["solicitacaoId"], "fase": processo["fase"], "data_inicio": processo["data_inicio"], "data_fim": processo["data_fim"]}
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
processo['inicio_processo'] = datetime.now()
|
|
23
|
+
await self.__db.tempo_processos.insert_one(processo)
|
|
24
|
+
return True
|
|
25
|
+
except Exception as e:
|
|
26
|
+
print(f"❌ Erro ao inserir o processo: {e}")
|
|
27
|
+
return False
|
|
28
|
+
|
|
29
|
+
async def atualizar_processo(self, *, solicitacaoId: int, fase: int, data_inicio: str, data_fim: str) -> bool:
|
|
30
|
+
try:
|
|
31
|
+
processo_no_db = await self.__db.tempo_processos.find_one(
|
|
32
|
+
{"solicitacaoId": solicitacaoId, "fase": fase, "data_inicio": data_inicio, "data_fim": data_fim}
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
if processo_no_db is None:
|
|
36
|
+
return False
|
|
37
|
+
|
|
38
|
+
processo_no_db['fim_processo'] = datetime.now()
|
|
39
|
+
tempo_de_processo = self._tempo_de_processo(processo_no_db['inicio_processo'], processo_no_db['fim_processo'])
|
|
40
|
+
processo_no_db['tempo_de_processo'] = tempo_de_processo
|
|
41
|
+
|
|
42
|
+
await self.__db.tempo_processos.replace_one(
|
|
43
|
+
{"solicitacaoId": solicitacaoId, "fase": fase, "data_inicio": data_inicio, "data_fim": data_fim},
|
|
44
|
+
processo_no_db
|
|
45
|
+
)
|
|
46
|
+
return True
|
|
47
|
+
except Exception as e:
|
|
48
|
+
print(f"❌ Erro ao atualizar o processo: {e}")
|
|
49
|
+
return False
|
|
50
|
+
|
|
51
|
+
def _tempo_de_processo(self, tempo_inicio: datetime, tempo_fim: datetime) -> str | None:
|
|
52
|
+
if tempo_inicio:
|
|
53
|
+
delta = tempo_inicio - tempo_fim
|
|
54
|
+
total_segundos = int(delta.total_seconds())
|
|
55
|
+
|
|
56
|
+
horas = total_segundos // 3600
|
|
57
|
+
minutos = (total_segundos % 3600) // 60
|
|
58
|
+
segundos = total_segundos % 60
|
|
59
|
+
|
|
60
|
+
tempo_formatado = f"{horas:02d}:{minutos:02d}:{segundos:02d}"
|
|
61
|
+
return tempo_formatado
|
|
62
|
+
|
|
63
|
+
return None
|
|
@@ -9,23 +9,24 @@ class EFaseRetificacao(Enum):
|
|
|
9
9
|
ExtraindoDadosDoXml = 4
|
|
10
10
|
AguardandoRubrica = 5
|
|
11
11
|
EstruturandoXmlAberturaCompetencia = 6
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
12
|
+
EstruturandoXmlInclusaoRubricas = 7
|
|
13
|
+
EstruturandoXmlExclusaoPagamentos = 8
|
|
14
|
+
EstruturandoXmlRetificacaoRemuneracao = 9
|
|
15
|
+
EstruturandoXmlInclusaoPagamentos = 10
|
|
16
|
+
EstruturandoXmlDesligamento = 11
|
|
17
|
+
EstruturandoXmlFechamentoCompetencia = 12
|
|
18
|
+
AberturaDeCompetencia = 13
|
|
19
|
+
ConsultandoESocialAberturaCompetencia = 14
|
|
20
|
+
InclusaoDasRubricas = 15
|
|
21
|
+
ConsultandoESocialInclusaoRubricas = 16
|
|
22
|
+
ExclusaoDePagamentos = 17
|
|
23
|
+
ConsultandoESocialExclusaoPagamentos = 18
|
|
24
|
+
RetificacaoDaRemuneracao = 19
|
|
25
|
+
ConsultandoESocialRetificacaoRemuneracao = 20
|
|
26
|
+
InclusaoDosPagamentos = 21
|
|
27
|
+
ConsultandoESocialInclusaoPagamentos = 22
|
|
28
|
+
Desligamento = 23
|
|
29
|
+
ConsultandoESocialDesligamento = 24
|
|
30
|
+
FechamentoDeCompetencia = 25
|
|
31
|
+
ConsultandoESocialFechamentoCompetencia = 26
|
|
32
|
+
Finalizado = 27
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import asyncio
|
|
2
|
+
import aio_pika
|
|
2
3
|
import json
|
|
3
4
|
|
|
4
|
-
|
|
5
5
|
class RabbitMQConsumer:
|
|
6
6
|
def __init__(
|
|
7
7
|
self,
|
|
8
|
+
*,
|
|
8
9
|
host: str,
|
|
9
10
|
queue: str,
|
|
10
11
|
username: str,
|
|
11
12
|
password: str,
|
|
12
|
-
vhost: str ="/",
|
|
13
|
+
vhost: str = "/",
|
|
13
14
|
):
|
|
14
15
|
self.host = host
|
|
15
16
|
self.queue = queue
|
|
@@ -18,39 +19,41 @@ class RabbitMQConsumer:
|
|
|
18
19
|
self.vhost = vhost
|
|
19
20
|
self.connection = None
|
|
20
21
|
self.channel = None
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
virtual_host=self.vhost,
|
|
22
|
+
|
|
23
|
+
async def connect(self):
|
|
24
|
+
self.connection = await aio_pika.connect_robust(
|
|
25
|
+
host=self.host,
|
|
26
|
+
login=self.username,
|
|
27
|
+
password=self.password,
|
|
28
|
+
virtualhost=self.vhost,
|
|
29
29
|
heartbeat=600,
|
|
30
|
-
blocked_connection_timeout=1200,
|
|
31
30
|
)
|
|
32
|
-
|
|
33
|
-
self.
|
|
34
|
-
self.channel =
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def start_consuming(self, callback):
|
|
38
|
-
def on_message(ch, method, properties, body):
|
|
39
|
-
mensagem = json.loads(body)
|
|
40
|
-
callback(mensagem)
|
|
41
|
-
ch.basic_ack(delivery_tag=method.delivery_tag)
|
|
42
|
-
self.close()
|
|
43
|
-
|
|
31
|
+
self.channel = await self.connection.channel()
|
|
32
|
+
await self.channel.set_qos(prefetch_count=1)
|
|
33
|
+
await self.channel.declare_queue(self.queue, durable=True)
|
|
34
|
+
|
|
35
|
+
async def start_consuming(self, callback):
|
|
44
36
|
if not self.channel:
|
|
45
37
|
raise RuntimeError("❌ Canal RabbitMQ não conectado. Chame connect() antes.")
|
|
46
38
|
|
|
47
|
-
self.channel.
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
39
|
+
queue = await self.channel.get_queue(self.queue)
|
|
40
|
+
|
|
41
|
+
async def on_message(message):
|
|
42
|
+
async with message.process():
|
|
43
|
+
try:
|
|
44
|
+
mensagem = json.loads(message.body.decode())
|
|
45
|
+
await callback(mensagem) # aqui sim passa o DTO
|
|
46
|
+
except Exception as e:
|
|
47
|
+
print(f"❌ Erro ao processar mensagem: {e}")
|
|
48
|
+
|
|
49
|
+
await queue.consume(on_message) # registra callback
|
|
50
|
+
|
|
51
|
+
print(f'[*] Aguardando mensagens na fila "{self.queue}". Para sair pressione CTRL+C')
|
|
52
|
+
|
|
53
|
+
# Mantém o consumer rodando
|
|
54
|
+
await asyncio.Future()
|
|
55
|
+
|
|
53
56
|
|
|
54
|
-
def close(self):
|
|
57
|
+
async def close(self):
|
|
55
58
|
if self.connection:
|
|
56
|
-
self.connection.close()
|
|
59
|
+
await self.connection.close()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: libretificacaotjcore
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.46
|
|
4
4
|
Summary: Biblioteca para centralizar conexao com filas no rabbit e banco de dados no mongodb para os servicos de retificacao da TJ
|
|
5
5
|
Author-email: Jhonatan Azevedo <dev.azevedo@outlook.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/seu-usuario/libretificacaotjcore
|
|
@@ -2,22 +2,24 @@ libretificacaotjcore/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hS
|
|
|
2
2
|
libretificacaotjcore/database/__init__.py,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
|
|
3
3
|
libretificacaotjcore/database/arquivo_repository.py,sha256=Wv42CWjddS8RPVR3aAOGwuFuLyGqmgq-TXOc-V0BTvE,2154
|
|
4
4
|
libretificacaotjcore/database/certificado_repository.py,sha256=LF3rV1rQmRGZVB4wPh_vmDj81Gf_env_5hqtTbxXNFM,1396
|
|
5
|
-
libretificacaotjcore/database/config_db.py,sha256=
|
|
5
|
+
libretificacaotjcore/database/config_db.py,sha256=K7N0p3Q3ldGXsOJpZHC3XwDWNxjuKZbtd22uMv_-6BE,2572
|
|
6
6
|
libretificacaotjcore/database/protocolo_repository.py,sha256=kb-mXxiOYDPbrPbYMhOb9xDZHknUdVSfVlmQ_Cn0l1s,3788
|
|
7
|
+
libretificacaotjcore/database/rubrica_repository.py,sha256=BVZLukKVH1YKRgPkk18aqck90DdNGrqv4cYr1IRSbL4,1130
|
|
8
|
+
libretificacaotjcore/database/tempo_processo_repository.py,sha256=XY8MQge8VE2BBe3IxNKdk-EE3seMi7P1xDL4lm5Bupo,2730
|
|
7
9
|
libretificacaotjcore/dtos/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
10
|
libretificacaotjcore/dtos/arquivo_dto.py,sha256=D4LLJZf-Z0XhJmOvu7nAcBq0j70m9TFtbgxI9ikHXQ0,1045
|
|
9
11
|
libretificacaotjcore/dtos/solicitacao_dto.py,sha256=dmI-JGgE0wZ9zXqej6pqSIIaopkROnBQo2Hj3pEXcZ8,2576
|
|
10
12
|
libretificacaotjcore/enums/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
|
-
libretificacaotjcore/enums/e_eventos.py,sha256=
|
|
12
|
-
libretificacaotjcore/enums/e_fase_retificacao.py,sha256=
|
|
13
|
+
libretificacaotjcore/enums/e_eventos.py,sha256=4NICIKFpxEvxMbHu_kcKqNXqylDETcr6qY1tK2bKmi4,207
|
|
14
|
+
libretificacaotjcore/enums/e_fase_retificacao.py,sha256=v7ERN6MuhdiuT2Yhzu5yzvR6rpKaxqoNMKrBlk4zhkY,1074
|
|
13
15
|
libretificacaotjcore/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
16
|
libretificacaotjcore/services/crypto_pass_service.py,sha256=9D0vyjan6f_8AfNxGkLpGdvyMpojsJq_AAySpv_zKMc,740
|
|
15
17
|
libretificacaotjcore/services/file_service.py,sha256=14CJokBbrsryQGmL0_unH2QKZpnteEAfxf5CPFdv6cE,2075
|
|
16
|
-
libretificacaotjcore/services/rabbitmq_consumer.py,sha256=
|
|
18
|
+
libretificacaotjcore/services/rabbitmq_consumer.py,sha256=yRS3sAkaMIIn8Y06icwkO1bpddlLC7BmNSHJVhUalzY,1818
|
|
17
19
|
libretificacaotjcore/services/rabbitmq_publisher.py,sha256=xsb9LmIuZizzq5lxnEEZKMK3U952KSQ2oqlTBZi2Lt8,1787
|
|
18
20
|
libretificacaotjcore/services/request_servico_api.py,sha256=G7vnmvOfwrCGL-Jy_5tCKG-l5E00OCkJfkuoa5Y6sHo,613
|
|
19
21
|
libretificacaotjcore/services/s3_service.py,sha256=HKR_jt2H3XdV1PCzo5R5bnhmoQ3I46Yn5IqAvVPhsjs,2946
|
|
20
|
-
libretificacaotjcore-0.1.
|
|
21
|
-
libretificacaotjcore-0.1.
|
|
22
|
-
libretificacaotjcore-0.1.
|
|
23
|
-
libretificacaotjcore-0.1.
|
|
22
|
+
libretificacaotjcore-0.1.46.dist-info/METADATA,sha256=V_FREYB7uKCZMVNsy3gW5CQCEdDltUN25RU7HCpgASQ,2564
|
|
23
|
+
libretificacaotjcore-0.1.46.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
24
|
+
libretificacaotjcore-0.1.46.dist-info/top_level.txt,sha256=J9vnz_X9OUnxC-eXHiAzlc9xIrWBwZ5bgnIDQIIFY4c,21
|
|
25
|
+
libretificacaotjcore-0.1.46.dist-info/RECORD,,
|
|
File without changes
|
{libretificacaotjcore-0.1.37.dist-info → libretificacaotjcore-0.1.46.dist-info}/top_level.txt
RENAMED
|
File without changes
|