Nueva mejoras Y estabilidad

This commit is contained in:
2025-12-26 22:27:20 -06:00
parent 203859b22a
commit ac96cb1f23
23 changed files with 1841 additions and 480 deletions

View File

@@ -0,0 +1,93 @@
using System.Diagnostics.Tracing;
using MicroORM.Interfaces;
using MieSystem.Models;
namespace MieSystem.Services;
public class AsistenciaService
{
private readonly IRepository<Asistencia> _repo;
public AsistenciaService(IRepository<Asistencia> expe)
{
_repo = expe;
}
public Task<int> SaveAsync(Asistencia expediente)
{
return _repo.SaveAsync(expediente);
}
public Task<Asistencia?> GetByIdAsync(object id)
{
return _repo.GetByIdAsync(id);
}
public Task<IEnumerable<Asistencia>> GetAllAsync()
{
return _repo.GetAllAsync();
}
public Task<IEnumerable<Asistencia>> GetAsistenciasPorMesAsync(int añoSeleccionado, int mesSeleccionado)
{
var sql = @"
SELECT
id,
expediente_id as ExpedienteId,
fecha,
estado,
hora_entrada as HoraEntrada,
hora_salida as HoraSalida,
observaciones,
fecha_registro as FechaRegistro,
usuario_registro as UsuarioRegistro
FROM asistencia
WHERE EXTRACT(YEAR FROM fecha) = @Anio
AND EXTRACT(MONTH FROM fecha) = @Mes
ORDER BY fecha, expediente_id";
return _repo.QueryAsync<Asistencia>(sql, new {Anio = añoSeleccionado, Mes = mesSeleccionado});
}
public Task<EstadisticasMes?> GetEstadisticasMesAsync(int año, int mes)
{
var sql = @"
SELECT
COALESCE(COUNT(*), 0) as Total,
COALESCE(COUNT(CASE WHEN estado = 'P' THEN 1 END), 0) as Presentes,
COALESCE(COUNT(CASE WHEN estado = 'T' THEN 1 END), 0) as Tardes,
COALESCE(COUNT(CASE WHEN estado = 'F' THEN 1 END), 0) as Faltas,
COALESCE(ROUND(
COUNT(CASE WHEN estado = 'P' THEN 1 END) * 100.0 /
NULLIF(COUNT(*), 0),
2
), 0) as PorcentajePresentes,
COALESCE(ROUND(
COUNT(CASE WHEN estado = 'T' THEN 1 END) * 100.0 /
NULLIF(COUNT(*), 0),
2
), 0) as PorcentajeTardes,
COALESCE(ROUND(
COUNT(CASE WHEN estado = 'F' THEN 1 END) * 100.0 /
NULLIF(COUNT(*), 0),
2
), 0) as PorcentajeFaltas
FROM asistencia
WHERE EXTRACT(YEAR FROM fecha) = @Anio
AND EXTRACT(MONTH FROM fecha) = @Mes";
return _repo.QuerySingleAsync<EstadisticasMes?>(sql, new { Anio = año, Mes = mes });
}
public bool GuardarAsistenciasMasivasAsync(List<Asistencia> lst)
{
try
{
_repo.SaveAsyncList(lst);
return true;
}
catch (Exception e)
{
Console.WriteLine(e);
return true;
}
}
}

View File

@@ -0,0 +1,35 @@
using MicroORM.Interfaces;
using MieSystem.Models;
namespace MieSystem.Services;
public class ExpedienteService
{
private readonly IRepository<Expediente> _repo;
public ExpedienteService(IRepository<Expediente> expe)
{
_repo = expe;
}
public Task<int> SaveAsync(Expediente expediente)
{
return _repo.SaveAsync(expediente);
}
public Task<Expediente?> GetByIdAsync(object id)
{
return _repo.GetByIdAsync(id);
}
public Task<IEnumerable<Expediente>> GetAllAsync()
{
return _repo.GetAllAsync();
}
public Task<IEnumerable<Expediente>> GetActivosAsync()
{
return _repo.GetAllAsync(e=> e.Activo == true);
}
}