feat(access): paridad funcional de verificacion peaton vs conductor y pulsos a barrera/molinete segun desktop pct_view

This commit is contained in:
Carlos Tello
2026-10-14 08:36:35 -03:00
parent d80a4dba74
commit 1f2b029e39
11 changed files with 345 additions and 15 deletions
+71
View File
@@ -42,6 +42,77 @@ class HardwareService:
cursor.execute(query, (modulo_id,))
return cursor.fetchone()
@classmethod
def obtener_tipo_acceso(cls, modulo_id: int) -> int:
"""
Obtiene el tipo_acceso_id (CategoriaID = 15 de MdlCatVal) resolviendo si
es un módulo virtual hacia su módulo físico asociado (ModuloEntradaID o ModuloSalidaID).
Valores estándar de CatVal (Cat 15):
1: Puerta
2: Molinete
7: Molinete Club
3: Barrera de Estado
4: Controlado
5: Barrera Pulso
6: Barrera Doble Pulso
"""
if not modulo_id:
return 0
mdl = cls.obtener_info_modulo(modulo_id)
if not mdl:
return 0
cat_map = {}
try:
with db_session() as conn:
cursor = conn.cursor()
cursor.execute(
"SELECT CategoriaID, ValorID FROM MdlCatVal WHERE ModuloID = %s",
(modulo_id,),
)
cat_map = {row[0]: row[1] for row in cursor.fetchall()}
except Exception:
pass
tipo_modulo_id = cat_map.get(2, 0)
sentido_id = cat_map.get(4, 0)
nombre_upper = (mdl.get("Nombre") or "").upper()
target_id = modulo_id
if tipo_modulo_id == 6 or mdl.get("Address", 0) >= 90:
if (sentido_id == 1 or "ENTRADA" in nombre_upper or "INGRESO" in nombre_upper) and mdl.get("ModuloEntradaID"):
target_id = mdl["ModuloEntradaID"]
elif (sentido_id == 2 or "SALIDA" in nombre_upper or "EGRESO" in nombre_upper) and mdl.get("ModuloSalidaID"):
target_id = mdl["ModuloSalidaID"]
target_cat_map = {}
if target_id != modulo_id:
try:
with db_session() as conn:
cursor = conn.cursor()
cursor.execute(
"SELECT CategoriaID, ValorID FROM MdlCatVal WHERE ModuloID = %s",
(target_id,),
)
target_cat_map = {row[0]: row[1] for row in cursor.fetchall()}
except Exception:
pass
else:
target_cat_map = cat_map
tipo_acceso = target_cat_map.get(15) or cat_map.get(15, 3)
return int(tipo_acceso)
@classmethod
def es_acceso_peatonal(cls, modulo_id: int) -> bool:
"""
Devuelve True si el acceso está configurado como Puerta (1), Molinete (2) o Molinete Club (7).
Idéntico a pct_view.py:2862 (`tipo_acc_mod in (1, 2, 7)`).
"""
tipo_acceso = cls.obtener_tipo_acceso(modulo_id)
return tipo_acceso in (1, 2, 7)
@classmethod
def encolar_apertura(
cls, modulo_id: int, ticket_id: int = 0, sin_ticket: bool = False