se agregó endpoint de ejemplo
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -552,66 +552,99 @@ export class EquipoService {
|
||||
async contar_perifericos_antiguedad(
|
||||
impresion: string[],
|
||||
digitalizacion: string[],
|
||||
): Promise<any> {
|
||||
const totalImpresion = this.contar_tipoEquipos(impresion);
|
||||
const totalDigitalizacion = this.contar_tipoEquipos(digitalizacion);
|
||||
|
||||
): Promise<{
|
||||
impresion: { antiguedad: any; total: number; porcentaje: string }[];
|
||||
digitalizacion: { antiguedad: any; total: number; porcentaje: string }[];
|
||||
}> {
|
||||
try {
|
||||
const countImpresion = await this.equipoRepository
|
||||
// Helper para obtener total por tipos de equipo (count simple, sin group by)
|
||||
const getTotalPorTipos = async (tipos: string[]): Promise<number> => {
|
||||
if (!tipos || tipos.length === 0) return 0;
|
||||
return this.equipoRepository
|
||||
.createQueryBuilder('e')
|
||||
.innerJoin('e.tipoEquipo', 't')
|
||||
.where('t.tipo_equipo IN (:...tipos)', { tipos })
|
||||
.getCount();
|
||||
};
|
||||
|
||||
// Ejecutar ambos totales en paralelo
|
||||
const [totalImpresion, totalDigitalizacion] = await Promise.all([
|
||||
getTotalPorTipos(impresion),
|
||||
getTotalPorTipos(digitalizacion),
|
||||
]);
|
||||
|
||||
// Obtener conteos por antiguedad para impresion
|
||||
const countImpresionPromise = this.equipoRepository
|
||||
.createQueryBuilder('e')
|
||||
.innerJoin('e.periferico', 'p')
|
||||
.where('p.periferico IN (:...periferico)', {
|
||||
periferico: impresion,
|
||||
})
|
||||
.innerJoin('e.tipoEquipo', 't')
|
||||
.where('p.periferico IN (:...periferico)', { periferico: impresion })
|
||||
.select(['e.antiguedad AS antiguedad'])
|
||||
.addSelect('COUNT(*) AS total')
|
||||
.groupBy('e.antiguedad')
|
||||
.getRawMany();
|
||||
const countDigitalizacion = await this.equipoRepository
|
||||
.createQueryBuilder('e')
|
||||
.innerJoin('e.perriferico', 'p')
|
||||
.where('p.periferico IN (:...periferico)', {
|
||||
tipo_equipo: digitalizacion,
|
||||
})
|
||||
.select(['e.antiguedad AS antiguedad'])
|
||||
.addSelect('COUNT(*) AS total')
|
||||
.addSelect('COUNT(e.id_equipo) AS total')
|
||||
.groupBy('e.antiguedad')
|
||||
.getRawMany();
|
||||
|
||||
// Obtener conteos por antiguedad para digitalizacion
|
||||
const countDigitalizacionPromise = this.equipoRepository
|
||||
.createQueryBuilder('e')
|
||||
.innerJoin('e.periferico', 'p')
|
||||
.innerJoin('e.tipoEquipo', 't')
|
||||
.where('p.periferico IN (:...periferico)', {
|
||||
periferico: digitalizacion,
|
||||
})
|
||||
.select(['e.antiguedad AS antiguedad'])
|
||||
.addSelect('COUNT(e.id_equipo) AS total')
|
||||
.groupBy('e.antiguedad')
|
||||
.getRawMany();
|
||||
|
||||
// Ejecutar ambas consultas en paralelo
|
||||
const [countImpresion, countDigitalizacion] = await Promise.all([
|
||||
countImpresionPromise,
|
||||
countDigitalizacionPromise,
|
||||
]);
|
||||
|
||||
// Tipo para salida
|
||||
interface Porcentaje {
|
||||
antiguedad: any;
|
||||
total: any;
|
||||
total: number;
|
||||
porcentaje: string;
|
||||
}
|
||||
|
||||
let porcentajesImpresion: Porcentaje[] = [];
|
||||
let porcentajesDigitalizacion: Porcentaje[] = [];
|
||||
|
||||
countImpresion.forEach(async (item) => {
|
||||
porcentajesImpresion.push({
|
||||
// Mapear resultados calculando porcentajes (evitar async dentro de map/forEach)
|
||||
const porcentajesImpresion: Porcentaje[] = countImpresion.map((item) => {
|
||||
const total = Number(item.total) || 0;
|
||||
const porcentaje =
|
||||
totalImpresion > 0
|
||||
? ((total / totalImpresion) * 100).toFixed(2)
|
||||
: '0.00';
|
||||
return {
|
||||
antiguedad: item.antiguedad,
|
||||
total: item.total,
|
||||
porcentaje: ((item.total / (await totalImpresion)) * 100).toFixed(2),
|
||||
});
|
||||
total,
|
||||
porcentaje,
|
||||
};
|
||||
});
|
||||
|
||||
countDigitalizacion.forEach(async (item) => {
|
||||
porcentajesDigitalizacion.push({
|
||||
antiguedad: item.antiguedad,
|
||||
total: item.total,
|
||||
porcentaje: (
|
||||
(item.total / (await totalDigitalizacion)) *
|
||||
100
|
||||
).toFixed(2),
|
||||
});
|
||||
});
|
||||
const porcentajesDigitalizacion: Porcentaje[] = countDigitalizacion.map(
|
||||
(item) => {
|
||||
const total = Number(item.total) || 0;
|
||||
const porcentaje =
|
||||
totalDigitalizacion > 0
|
||||
? ((total / totalDigitalizacion) * 100).toFixed(2)
|
||||
: '0.00';
|
||||
return {
|
||||
antiguedad: item.antiguedad,
|
||||
total,
|
||||
porcentaje,
|
||||
};
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
impresion: porcentajesDigitalizacion,
|
||||
digitalizacion: porcentajesImpresion,
|
||||
impresion: porcentajesImpresion,
|
||||
digitalizacion: porcentajesDigitalizacion,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error al contar equipos por tipo y uso:', error);
|
||||
console.error('Error en contar_perifericos_antiguedad:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
@@ -637,6 +670,7 @@ export class EquipoService {
|
||||
contar_impresoras_tipo_uso,
|
||||
contar_digitalizacion,
|
||||
contar_contar_digitalizacion_u,
|
||||
contar_perifericos_antiguedad,
|
||||
] = await Promise.all([
|
||||
this.contar_tipoEquipos_tipoUso(),
|
||||
this.contar_tipoEquipos_sistemasOperativos(equpos_pc),
|
||||
@@ -657,6 +691,7 @@ export class EquipoService {
|
||||
this.contar_periferico_tipoUso(impresoras),
|
||||
this.equipos_impesion_group(dijitales),
|
||||
this.contar_periferico_tipoUso(dijitales),
|
||||
this.contar_perifericos_antiguedad(impresoras, dijitales),
|
||||
]);
|
||||
|
||||
return {
|
||||
@@ -679,6 +714,7 @@ export class EquipoService {
|
||||
contar_impresoras_tipo_uso,
|
||||
contar_digitalizacion,
|
||||
contar_contar_digitalizacion_u,
|
||||
contar_perifericos_antiguedad,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user