GetDeviceThresholdAlarm
GetAreaThresholdAlarm
This commit is contained in:
@@ -25,14 +25,19 @@ type ThresholdAlarmService interface {
|
||||
ListActiveAlarms(ctx context.Context, req *dto.ListActiveAlarmRequest) (*dto.ListActiveAlarmResponse, error)
|
||||
// ListHistoricalAlarms 批量查询历史告警。
|
||||
ListHistoricalAlarms(ctx context.Context, req *dto.ListHistoricalAlarmRequest) (*dto.ListHistoricalAlarmResponse, error)
|
||||
|
||||
// CreateDeviceThresholdAlarm 创建一个设备阈值告警。
|
||||
CreateDeviceThresholdAlarm(ctx context.Context, req *dto.CreateDeviceThresholdAlarmDTO) error
|
||||
// UpdateDeviceThresholdAlarm 更新一个设备阈值告警。
|
||||
UpdateDeviceThresholdAlarm(ctx context.Context, taskID int, req *dto.UpdateDeviceThresholdAlarmDTO) error
|
||||
// GetDeviceThresholdAlarm 根据ID获取一个设备阈值告警任务。
|
||||
GetDeviceThresholdAlarm(ctx context.Context, taskID int) (*dto.DeviceThresholdAlarmDTO, error)
|
||||
// CreateAreaThresholdAlarm 创建一个区域阈值告警。
|
||||
CreateAreaThresholdAlarm(ctx context.Context, req *dto.CreateAreaThresholdAlarmDTO) error
|
||||
// UpdateAreaThresholdAlarm 更新一个区域阈值告警。
|
||||
UpdateAreaThresholdAlarm(ctx context.Context, taskID int, req *dto.UpdateAreaThresholdAlarmDTO) error
|
||||
// GetAreaThresholdAlarm 根据ID获取一个区域阈值告警任务。
|
||||
GetAreaThresholdAlarm(ctx context.Context, taskID int) (*dto.AreaThresholdAlarmDTO, error)
|
||||
}
|
||||
|
||||
// thresholdAlarmService 是 ThresholdAlarmService 接口的具体实现。
|
||||
@@ -254,6 +259,38 @@ func (s *thresholdAlarmService) UpdateDeviceThresholdAlarm(ctx context.Context,
|
||||
return err
|
||||
}
|
||||
|
||||
// GetDeviceThresholdAlarm 实现了根据ID获取一个设备阈值告警任务的逻辑。
|
||||
func (s *thresholdAlarmService) GetDeviceThresholdAlarm(ctx context.Context, taskID int) (*dto.DeviceThresholdAlarmDTO, error) {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "GetDeviceThresholdAlarm")
|
||||
|
||||
// 1. 使用 planRepo 查询任务
|
||||
t, err := s.planRepo.FindTaskByID(serviceCtx, taskID)
|
||||
if err != nil {
|
||||
return nil, err // 如果未找到或发生其他错误,直接返回
|
||||
}
|
||||
|
||||
// 2. 验证任务类型是否正确
|
||||
if t.Type != models.TaskTypeDeviceThresholdCheck {
|
||||
return nil, fmt.Errorf("任务 %d 不是一个设备阈值检查任务", taskID)
|
||||
}
|
||||
var params task.DeviceThresholdCheckParams
|
||||
err = t.ParseParameters(¶ms)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("任务 %d: 解析参数失败: %w", taskID, err)
|
||||
}
|
||||
|
||||
resp := &dto.DeviceThresholdAlarmDTO{
|
||||
ID: t.ID,
|
||||
DeviceID: params.DeviceID,
|
||||
SensorType: params.SensorType,
|
||||
Thresholds: params.Thresholds,
|
||||
Operator: params.Operator,
|
||||
Level: params.Level,
|
||||
}
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// CreateAreaThresholdAlarm 实现了创建一个区域阈值告警的逻辑。
|
||||
func (s *thresholdAlarmService) CreateAreaThresholdAlarm(ctx context.Context, req *dto.CreateAreaThresholdAlarmDTO) error {
|
||||
serviceCtx, logger := logs.Trace(ctx, s.ctx, "CreateAreaThresholdAlarm")
|
||||
@@ -374,3 +411,34 @@ func (s *thresholdAlarmService) UpdateAreaThresholdAlarm(ctx context.Context, ta
|
||||
_, err = s.planService.UpdatePlan(serviceCtx, plan, models.PlanTypeSystem)
|
||||
return err
|
||||
}
|
||||
|
||||
// GetAreaThresholdAlarm 实现了根据ID获取一个区域阈值告警任务的逻辑。
|
||||
func (s *thresholdAlarmService) GetAreaThresholdAlarm(ctx context.Context, taskID int) (*dto.AreaThresholdAlarmDTO, error) {
|
||||
serviceCtx := logs.AddFuncName(ctx, s.ctx, "GetAreaThresholdAlarm")
|
||||
|
||||
// 1. 使用 planRepo 查询任务
|
||||
t, err := s.planRepo.FindTaskByID(serviceCtx, taskID)
|
||||
if err != nil {
|
||||
return nil, err // 如果未找到或发生其他错误,直接返回
|
||||
}
|
||||
|
||||
// 2. 验证任务类型是否正确
|
||||
if t.Type != models.TaskTypeAreaCollectorThresholdCheck {
|
||||
return nil, fmt.Errorf("任务 %d 不是一个区域阈值检查任务", taskID)
|
||||
}
|
||||
var params task.AreaThresholdCheckParams
|
||||
err = t.ParseParameters(¶ms)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("任务 %d: 解析参数失败: %w", taskID, err)
|
||||
}
|
||||
|
||||
resp := &dto.AreaThresholdAlarmDTO{
|
||||
ID: t.ID,
|
||||
AreaControllerID: params.AreaControllerID,
|
||||
SensorType: params.SensorType,
|
||||
Thresholds: params.Thresholds,
|
||||
Operator: params.Operator,
|
||||
Level: params.Level,
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user