feat: complete Phases 2 to 5 inclusive - Access Core, Web Cockpit, Hardware enqueuing, Optical Scanner and QA (v0.5.0-beta)
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
# ==============================================================================
|
||||
# Servicio de Gestión de Estaciones de Trabajo (Workstations)
|
||||
# ==============================================================================
|
||||
from typing import List, Dict, Any
|
||||
from app.repositories.workstation_repository import WorkstationRepository
|
||||
from app.schemas.workstation_schema import WorkstationStatusResponse, LaneModuleDTO
|
||||
|
||||
|
||||
class WorkstationService:
|
||||
@staticmethod
|
||||
def obtener_estado_workstation(name: str) -> WorkstationStatusResponse:
|
||||
"""Determina si la tablet/workstation está registrada y qué carriles tiene asignados."""
|
||||
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=[],
|
||||
)
|
||||
|
||||
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"),
|
||||
)
|
||||
)
|
||||
|
||||
return WorkstationStatusResponse(
|
||||
workstation_name=nombre_oficial,
|
||||
is_control_post=len(modules_dto) > 0,
|
||||
workstation_id=wks_id,
|
||||
modules=modules_dto,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def listar_estaciones_disponibles() -> List[Dict[str, Any]]:
|
||||
"""Retorna el listado de todas las workstations disponibles para selección de supervisor."""
|
||||
rows = WorkstationRepository.listar_todas()
|
||||
return [{"workstation_id": r["WorkstationID"], "nombre": r["Nombre"].strip()} for r in rows]
|
||||
Reference in New Issue
Block a user