feat: implementacion completa de 8 modulos, sincronizador centinel, mcp y bitacora de errores
This commit is contained in:
@@ -44,4 +44,73 @@ class IncidentesDao {
|
||||
whereArgs: [id],
|
||||
);
|
||||
}
|
||||
|
||||
// Comentario explicativo: Marca un incidente como sincronizado (sincronizado=1) tras enviarse exitosamente a Centinel
|
||||
Future<int> marcarSincronizado(int id) async {
|
||||
final db = await _db.db;
|
||||
return db.update(
|
||||
'incidentes',
|
||||
{'sincronizado': 1},
|
||||
where: 'id = ?',
|
||||
whereArgs: [id],
|
||||
);
|
||||
}
|
||||
|
||||
// Comentario explicativo: Consulta incidentes aplicando filtros opcionales de cliente, operador, resolución y antigüedad para el módulo de Reportes
|
||||
Future<List<Map<String, dynamic>>> getFiltrados({
|
||||
String? clienteNombre,
|
||||
String? operador,
|
||||
int? resuelto,
|
||||
DateTime? desde,
|
||||
}) async {
|
||||
final db = await _db.db;
|
||||
final whereClauses = <String>[];
|
||||
final whereArgs = <dynamic>[];
|
||||
|
||||
if (clienteNombre != null && clienteNombre.isNotEmpty && clienteNombre != 'todos') {
|
||||
whereClauses.add('cliente_nombre = ?');
|
||||
whereArgs.add(clienteNombre);
|
||||
}
|
||||
if (operador != null && operador.isNotEmpty && operador != 'todos') {
|
||||
whereClauses.add('operador = ?');
|
||||
whereArgs.add(operador);
|
||||
}
|
||||
if (resuelto != null) {
|
||||
whereClauses.add('resuelto = ?');
|
||||
whereArgs.add(resuelto);
|
||||
}
|
||||
if (desde != null) {
|
||||
whereClauses.add('timestamp >= ?');
|
||||
whereArgs.add(desde.toIso8601String());
|
||||
}
|
||||
|
||||
final where = whereClauses.isNotEmpty ? whereClauses.join(' AND ') : null;
|
||||
return db.query(
|
||||
'incidentes',
|
||||
where: where,
|
||||
whereArgs: whereArgs.isNotEmpty ? whereArgs : null,
|
||||
orderBy: 'timestamp DESC',
|
||||
);
|
||||
}
|
||||
|
||||
// Comentario explicativo: Calcula métricas agregadas de incidentes (totales, resueltos, falsas alarmas) para las tarjetas KPI de reportes
|
||||
Future<Map<String, int>> getEstadisticas() async {
|
||||
final db = await _db.db;
|
||||
final totalRes = await db.rawQuery('SELECT COUNT(*) as c FROM incidentes');
|
||||
final resueltosRes = await db.rawQuery('SELECT COUNT(*) as c FROM incidentes WHERE resuelto = 1');
|
||||
final pendientesRes = await db.rawQuery('SELECT COUNT(*) as c FROM incidentes WHERE resuelto = 0');
|
||||
final falsasRes = await db.rawQuery("SELECT COUNT(*) as c FROM incidentes WHERE tipo LIKE '%falsa%'");
|
||||
|
||||
final total = (totalRes.isNotEmpty ? totalRes.first['c'] as int? : 0) ?? 0;
|
||||
final resueltos = (resueltosRes.isNotEmpty ? resueltosRes.first['c'] as int? : 0) ?? 0;
|
||||
final pendientes = (pendientesRes.isNotEmpty ? pendientesRes.first['c'] as int? : 0) ?? 0;
|
||||
final falsas = (falsasRes.isNotEmpty ? falsasRes.first['c'] as int? : 0) ?? 0;
|
||||
|
||||
return {
|
||||
'total': total,
|
||||
'resueltos': resueltos,
|
||||
'pendientes': pendientes,
|
||||
'falsas': falsas,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user