|
|
|
|
@ -278,19 +278,90 @@ namespace Haoliang.Core.Services
|
|
|
|
|
#region ========== 告警服务 ==========
|
|
|
|
|
public class AlarmService : IAlarmService
|
|
|
|
|
{
|
|
|
|
|
public Task<IEnumerable<Alarm>> GetAllAlarmsAsync() => Task.FromResult<IEnumerable<Alarm>>(new List<Alarm>());
|
|
|
|
|
public Task<IEnumerable<Alarm>> GetAlarmsByTypeAsync(AlarmType type) => Task.FromResult<IEnumerable<Alarm>>(new List<Alarm>());
|
|
|
|
|
public Task<IEnumerable<Alarm>> GetActiveAlarmsAsync() => Task.FromResult<IEnumerable<Alarm>>(new List<Alarm>());
|
|
|
|
|
public Task<Alarm?> GetAlarmByIdAsync(int alarmId) => Task.FromResult<Alarm?>(null);
|
|
|
|
|
public Task<Alarm> CreateAlarmAsync(Alarm alarm) => Task.FromResult(alarm);
|
|
|
|
|
public Task<Alarm?> UpdateAlarmAsync(int alarmId, Alarm alarm) => Task.FromResult<Alarm?>(null);
|
|
|
|
|
public Task<bool> DeleteAlarmAsync(int alarmId) => Task.FromResult(false);
|
|
|
|
|
public Task<bool> ResolveAlarmAsync(int alarmId, string? resolutionNote) => Task.FromResult(false);
|
|
|
|
|
private readonly IAlarmRepository _alarmRepository;
|
|
|
|
|
|
|
|
|
|
public AlarmService(IAlarmRepository alarmRepository)
|
|
|
|
|
{
|
|
|
|
|
_alarmRepository = alarmRepository;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<Alarm>> GetAllAlarmsAsync()
|
|
|
|
|
{
|
|
|
|
|
return await _alarmRepository.GetAllAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<Alarm>> GetAlarmsByTypeAsync(AlarmType type)
|
|
|
|
|
{
|
|
|
|
|
return await _alarmRepository.GetAlarmsByTypeAsync(type.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<Alarm>> GetActiveAlarmsAsync()
|
|
|
|
|
{
|
|
|
|
|
return await _alarmRepository.GetActiveAlarmsAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<Alarm?> GetAlarmByIdAsync(int alarmId)
|
|
|
|
|
{
|
|
|
|
|
return await _alarmRepository.GetByIdAsync(alarmId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<Alarm> CreateAlarmAsync(Alarm alarm)
|
|
|
|
|
{
|
|
|
|
|
alarm.CreatedAt = DateTime.Now;
|
|
|
|
|
alarm.OccurrenceTime = DateTime.Now;
|
|
|
|
|
await _alarmRepository.AddAsync(alarm);
|
|
|
|
|
await _alarmRepository.SaveAsync();
|
|
|
|
|
return alarm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<Alarm?> UpdateAlarmAsync(int alarmId, Alarm alarm)
|
|
|
|
|
{
|
|
|
|
|
var existing = await _alarmRepository.GetByIdAsync(alarmId);
|
|
|
|
|
if (existing == null) return null;
|
|
|
|
|
|
|
|
|
|
existing.AlarmType = alarm.AlarmType;
|
|
|
|
|
existing.AlarmContent = alarm.AlarmContent;
|
|
|
|
|
existing.AlarmLevel = alarm.AlarmLevel;
|
|
|
|
|
existing.IsResolved = alarm.IsResolved;
|
|
|
|
|
existing.ResolutionNote = alarm.ResolutionNote;
|
|
|
|
|
|
|
|
|
|
_alarmRepository.Update(existing);
|
|
|
|
|
await _alarmRepository.SaveAsync();
|
|
|
|
|
return existing;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<bool> DeleteAlarmAsync(int alarmId)
|
|
|
|
|
{
|
|
|
|
|
var alarm = await _alarmRepository.GetByIdAsync(alarmId);
|
|
|
|
|
if (alarm == null) return false;
|
|
|
|
|
|
|
|
|
|
_alarmRepository.Remove(alarm);
|
|
|
|
|
return await _alarmRepository.SaveAsync() > 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<bool> ResolveAlarmAsync(int alarmId, string? resolutionNote)
|
|
|
|
|
{
|
|
|
|
|
return await _alarmRepository.ResolveAlarmAsync(alarmId, resolutionNote, "System");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<bool> AcknowledgeAlarmAsync(int alarmId, string? acknowledgeNote) => Task.FromResult(false);
|
|
|
|
|
public Task<IEnumerable<Alarm>> GetDeviceAlarmsAsync(int deviceId, int days = 7) => Task.FromResult<IEnumerable<Alarm>>(new List<Alarm>());
|
|
|
|
|
public Task<IEnumerable<Alarm>> GetCriticalAlarmsAsync() => Task.FromResult<IEnumerable<Alarm>>(new List<Alarm>());
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<Alarm>> GetDeviceAlarmsAsync(int deviceId, int days = 7)
|
|
|
|
|
{
|
|
|
|
|
return await _alarmRepository.GetAlarmsByDeviceIdAsync(deviceId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<Alarm>> GetCriticalAlarmsAsync()
|
|
|
|
|
{
|
|
|
|
|
return await _alarmRepository.GetAlarmsByLevelAsync("Critical");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Task<AlarmStatistics> GetAlarmStatisticsAsync(DateTime date) => Task.FromResult<AlarmStatistics>(null);
|
|
|
|
|
public Task<IEnumerable<Alarm>> GetAlarmsByDateRangeAsync(DateTime startDate, DateTime endDate) => Task.FromResult<IEnumerable<Alarm>>(new List<Alarm>());
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<Alarm>> GetAlarmsByDateRangeAsync(DateTime startDate, DateTime endDate)
|
|
|
|
|
{
|
|
|
|
|
return await _alarmRepository.GetAlarmsByDateRangeAsync(startDate, endDate);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class AlarmRuleService : IAlarmRuleService
|
|
|
|
|
|