libretificacaotjcore 0.1.2__py3-none-any.whl → 0.1.4__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.

@@ -1,3 +1,5 @@
1
+ from pymongo.errors import BulkWriteError
2
+
1
3
  class ArquivoRepository:
2
4
  def __init__(self, db):
3
5
  self.__db = db
@@ -21,6 +23,23 @@ class ArquivoRepository:
21
23
  except Exception as e:
22
24
  print(f"❌ Erro ao inserir o arquivo: {e}")
23
25
  return False
26
+
27
+ async def inserir_arquivos_em_lote(self, arquivos: list[dict]) -> bool:
28
+ try:
29
+ if not arquivos:
30
+ return False
31
+
32
+ filtros = [{"SolicitacaoId": a["solicitacaoId"], "cpf": a["cpf"]} for a in arquivos]
33
+ await self.__db.arquivos.delete_many({"$or": filtros})
34
+
35
+ await self.__db.arquivos.insert_many(arquivos)
36
+ return True
37
+ except BulkWriteError as bwe:
38
+ print(f"❌ Erro de escrita em lote: {bwe.details}")
39
+ return False
40
+ except Exception as e:
41
+ print(f"❌ Erro ao inserir arquivos em lote: {e}")
42
+ return False
24
43
 
25
44
  async def remover_arquivo(self, solicitacaoId: int) -> bool:
26
45
  try:
@@ -13,21 +13,22 @@ class ConfigDb:
13
13
  self.client = motor.motor_asyncio.AsyncIOMotorClient(
14
14
  f"mongodb://{self.host}:{self.port}"
15
15
  )
16
- self.db = self.client[self.db_name]
16
+ self.__db = self.client[self.db_name]
17
17
  self.db_initialized = False
18
18
 
19
19
 
20
20
  async def criar_schema(self):
21
21
  global _db_initialized
22
22
  if not self.db_initialized:
23
- if "arquivos" not in (await self.db.list_collection_names()):
24
- await self.db.create_collection("arquivos")
23
+ if "arquivos" not in (await self.__db.list_collection_names()):
24
+ await self.__db.create_collection("arquivos")
25
25
 
26
- await self.db.arquivos.create_index([("cnpj", 1)])
27
- await self.db.arquivos.create_index([("SolicitacaoId", 1)])
28
- await self.db.arquivos.create_index([("id", 1)], unique=True)
26
+ await self.__db.arquivos.create_index([("cnpj", 1)])
27
+ await self.__db.arquivos.create_index([("SolicitacaoId", 1)])
28
+ await self.__db.arquivos.create_index([("id", 1)], unique=True)
29
+ await self.__db.arquivos.create_index([("SolicitacaoId", 1), ("cpf", 1)], unique=True)
29
30
  self.db_initialized = True
30
31
 
31
32
  async def get_db(self):
32
33
  await self.criar_schema()
33
- return self.db
34
+ return self.__db
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: libretificacaotjcore
3
- Version: 0.1.2
3
+ Version: 0.1.4
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
@@ -1,12 +1,12 @@
1
1
  libretificacaotjcore/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  libretificacaotjcore/database/__init__.py,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
3
- libretificacaotjcore/database/arquivo_repository.py,sha256=Mt-5IWp7GVbMTAsCdFhi3TkIf2d__ccCGgJI_z-PE2Y,1118
4
- libretificacaotjcore/database/config_db.py,sha256=bixGQjK-QHk8KAqSadHMHZe1mU57FbVXI0rdW0PvNSs,1178
3
+ libretificacaotjcore/database/arquivo_repository.py,sha256=ks1dbRmrDiFfqxpVXodYZVeHg00_90oRVoBJ9BNsXv4,1833
4
+ libretificacaotjcore/database/config_db.py,sha256=ydY83Xn16DcAO-apH1nIJ1hKL_38hEHeUKg5R8v8ZJI,1292
5
5
  libretificacaotjcore/dtos/solicitacao_dto.py,sha256=A0QU6MwuyK6Z2vYy4FknSAOfebpY4txB-YmgpFhAVCY,2460
6
6
  libretificacaotjcore/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
7
  libretificacaotjcore/services/rabbitmq_consumer.py,sha256=a25mRHjbkgO3lkdCJ5NpJfWAGHhVkQDCRDR2t8hMNAI,1710
8
8
  libretificacaotjcore/services/s3_service.py,sha256=HKR_jt2H3XdV1PCzo5R5bnhmoQ3I46Yn5IqAvVPhsjs,2946
9
- libretificacaotjcore-0.1.2.dist-info/METADATA,sha256=qkfhEnoBgY0Oh8xzJV0l94SX2ll4LSEjbW-ZUkMRfiw,1368
10
- libretificacaotjcore-0.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
- libretificacaotjcore-0.1.2.dist-info/top_level.txt,sha256=J9vnz_X9OUnxC-eXHiAzlc9xIrWBwZ5bgnIDQIIFY4c,21
12
- libretificacaotjcore-0.1.2.dist-info/RECORD,,
9
+ libretificacaotjcore-0.1.4.dist-info/METADATA,sha256=4T88j8qcx52xKkKYuB3nKpiwMwXKmplv-iLc2pRK9C8,1368
10
+ libretificacaotjcore-0.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
+ libretificacaotjcore-0.1.4.dist-info/top_level.txt,sha256=J9vnz_X9OUnxC-eXHiAzlc9xIrWBwZ5bgnIDQIIFY4c,21
12
+ libretificacaotjcore-0.1.4.dist-info/RECORD,,