feat(real-data): carga dinamica de workstations y tickets/movimientos reales desde SQL Server
This commit is contained in:
@@ -155,3 +155,29 @@ class AccessService:
|
||||
)
|
||||
for f in filas
|
||||
]
|
||||
|
||||
@staticmethod
|
||||
def obtener_ultimos_movimientos(limite: int = 50) -> List[dict]:
|
||||
"""Retorna los últimos movimientos reales registrados en SQL Server mvthist."""
|
||||
from app.schemas.access_schema import MovementHistoryDTO
|
||||
filas = AccessRepository.listar_ultimos_movimientos(limite)
|
||||
resultado = []
|
||||
for f in filas:
|
||||
fh = f["FechaHora"]
|
||||
fh_str = fh.strftime("%Y-%m-%d %H:%M:%S") if isinstance(fh, datetime) else str(fh)
|
||||
resultado.append(
|
||||
MovementHistoryDTO(
|
||||
mvt_hist_id=f["MvtHistID"],
|
||||
ticket_id=f["TicketID"] or 0,
|
||||
sentido=str(f["Sentido"] or "Ingreso"),
|
||||
patente=f.get("Patente"),
|
||||
apellido=f.get("Apellido"),
|
||||
nombre=f.get("Nombre"),
|
||||
documento=f.get("Documento"),
|
||||
lote_codigo=None,
|
||||
modulo_nombre=f.get("ModuloNombre"),
|
||||
fecha_hora=fh_str,
|
||||
entidad=f.get("Entidad"),
|
||||
)
|
||||
)
|
||||
return resultado
|
||||
|
||||
@@ -3,50 +3,81 @@
|
||||
# ==============================================================================
|
||||
from typing import List, Dict, Any
|
||||
from app.repositories.workstation_repository import WorkstationRepository
|
||||
from app.schemas.workstation_schema import WorkstationStatusResponse, LaneModuleDTO
|
||||
from app.schemas.workstation_schema import (
|
||||
WorkstationStatusResponse,
|
||||
WorkstationConfigResponse,
|
||||
WorkstationItemDTO,
|
||||
LaneModuleDTO,
|
||||
)
|
||||
|
||||
|
||||
class WorkstationService:
|
||||
@staticmethod
|
||||
def obtener_estado_workstation(name: str) -> WorkstationStatusResponse:
|
||||
"""Determina si la tablet/workstation está registrada y qué carriles tiene asignados."""
|
||||
def obtener_config_workstation(name: str) -> WorkstationConfigResponse:
|
||||
"""Retorna la configuración esperada por el cliente web: id, name, entry_modules, exit_modules."""
|
||||
wks_row = WorkstationRepository.obtener_workstation_por_nombre(name)
|
||||
if not wks_row:
|
||||
return WorkstationStatusResponse(
|
||||
workstation_name=name,
|
||||
is_control_post=False,
|
||||
workstation_id=None,
|
||||
modules=[],
|
||||
return WorkstationConfigResponse(
|
||||
id=0,
|
||||
name=name,
|
||||
entry_modules=[],
|
||||
exit_modules=[],
|
||||
)
|
||||
|
||||
wks_id = wks_row["WorkstationID"]
|
||||
nombre_oficial = wks_row["Nombre"].strip()
|
||||
modulos_rows = WorkstationRepository.listar_modulos_por_workstation(wks_id)
|
||||
|
||||
modules_dto: List[LaneModuleDTO] = []
|
||||
for m in modulos_rows:
|
||||
# Determinamos si es entrada o salida según ModuloEntradaID o nombre
|
||||
es_entrada = bool(m.get("ModuloEntradaID")) or "ENTRADA" in m["Nombre"].upper()
|
||||
modules_dto.append(
|
||||
LaneModuleDTO(
|
||||
modulo_id=m["ModuloID"],
|
||||
nombre=m["Nombre"].strip(),
|
||||
address=m["Address"],
|
||||
grupo_modulos=m.get("GrupoModulos"),
|
||||
es_entrada=es_entrada,
|
||||
duracion_pulso=m.get("duracion_pulso"),
|
||||
)
|
||||
)
|
||||
entry_modules: List[LaneModuleDTO] = []
|
||||
exit_modules: List[LaneModuleDTO] = []
|
||||
|
||||
return WorkstationStatusResponse(
|
||||
workstation_name=nombre_oficial,
|
||||
is_control_post=len(modules_dto) > 0,
|
||||
workstation_id=wks_id,
|
||||
modules=modules_dto,
|
||||
for m in modulos_rows:
|
||||
nom = m["Nombre"].strip()
|
||||
nom_upper = nom.upper()
|
||||
if "SALIDA" in nom_upper or "EGRESO" in nom_upper:
|
||||
es_entrada = False
|
||||
elif "ENTRADA" in nom_upper or "INGRESO" in nom_upper:
|
||||
es_entrada = True
|
||||
else:
|
||||
es_entrada = not bool(m.get("ModuloEntradaID"))
|
||||
dto = LaneModuleDTO(
|
||||
id=m["ModuloID"],
|
||||
name=nom,
|
||||
address=m["Address"],
|
||||
type="ENTRY" if es_entrada else "EXIT",
|
||||
grupo_modulos=m.get("GrupoModulos"),
|
||||
es_entrada=es_entrada,
|
||||
duracion_pulso=m.get("duracion_pulso"),
|
||||
)
|
||||
if es_entrada:
|
||||
entry_modules.append(dto)
|
||||
else:
|
||||
exit_modules.append(dto)
|
||||
|
||||
return WorkstationConfigResponse(
|
||||
id=wks_id,
|
||||
name=nombre_oficial,
|
||||
entry_modules=entry_modules,
|
||||
exit_modules=exit_modules,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def listar_estaciones_disponibles() -> List[Dict[str, Any]]:
|
||||
"""Retorna el listado de todas las workstations disponibles para selección de supervisor."""
|
||||
def obtener_estado_workstation(name: str) -> WorkstationStatusResponse:
|
||||
"""Determina si la tablet/workstation está registrada y qué carriles tiene asignados."""
|
||||
cfg = WorkstationService.obtener_config_workstation(name)
|
||||
all_modules = cfg.entry_modules + cfg.exit_modules
|
||||
return WorkstationStatusResponse(
|
||||
workstation_name=cfg.name,
|
||||
is_control_post=len(all_modules) > 0,
|
||||
workstation_id=cfg.id,
|
||||
modules=all_modules,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def listar_estaciones_disponibles() -> List[WorkstationItemDTO]:
|
||||
"""Retorna el listado de todas las workstations reales desde la tabla wks de SQL Server."""
|
||||
rows = WorkstationRepository.listar_todas()
|
||||
return [{"workstation_id": r["WorkstationID"], "nombre": r["Nombre"].strip()} for r in rows]
|
||||
return [
|
||||
WorkstationItemDTO(id=r["WorkstationID"], name=r["Nombre"].strip())
|
||||
for r in rows
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user