实现列表查询活跃告警和历史告警
This commit is contained in:
65
internal/app/dto/alarm_converter.go
Normal file
65
internal/app/dto/alarm_converter.go
Normal file
@@ -0,0 +1,65 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
|
||||
)
|
||||
|
||||
// NewListActiveAlarmResponse 从模型数据创建活跃告警列表响应 DTO
|
||||
func NewListActiveAlarmResponse(data []models.ActiveAlarm, total int64, page, pageSize int) *ListActiveAlarmResponse {
|
||||
dtos := make([]ActiveAlarmDTO, len(data))
|
||||
for i, item := range data {
|
||||
dtos[i] = ActiveAlarmDTO{
|
||||
ID: item.ID,
|
||||
CreatedAt: item.CreatedAt,
|
||||
UpdatedAt: item.UpdatedAt,
|
||||
SourceType: item.SourceType,
|
||||
SourceID: item.SourceID,
|
||||
AlarmCode: item.AlarmCode,
|
||||
AlarmSummary: item.AlarmSummary,
|
||||
Level: item.Level,
|
||||
AlarmDetails: item.AlarmDetails,
|
||||
TriggerTime: item.TriggerTime,
|
||||
IsIgnored: item.IsIgnored,
|
||||
IgnoredUntil: item.IgnoredUntil,
|
||||
LastNotifiedAt: item.LastNotifiedAt,
|
||||
}
|
||||
}
|
||||
|
||||
return &ListActiveAlarmResponse{
|
||||
List: dtos,
|
||||
Pagination: PaginationDTO{
|
||||
Total: total,
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// NewListHistoricalAlarmResponse 从模型数据创建历史告警列表响应 DTO
|
||||
func NewListHistoricalAlarmResponse(data []models.HistoricalAlarm, total int64, page, pageSize int) *ListHistoricalAlarmResponse {
|
||||
dtos := make([]HistoricalAlarmDTO, len(data))
|
||||
for i, item := range data {
|
||||
dtos[i] = HistoricalAlarmDTO{
|
||||
ID: item.ID,
|
||||
SourceType: item.SourceType,
|
||||
SourceID: item.SourceID,
|
||||
AlarmCode: item.AlarmCode,
|
||||
AlarmSummary: item.AlarmSummary,
|
||||
Level: item.Level,
|
||||
AlarmDetails: item.AlarmDetails,
|
||||
TriggerTime: item.TriggerTime,
|
||||
ResolveTime: item.ResolveTime,
|
||||
ResolveMethod: item.ResolveMethod,
|
||||
ResolvedBy: item.ResolvedBy,
|
||||
}
|
||||
}
|
||||
|
||||
return &ListHistoricalAlarmResponse{
|
||||
List: dtos,
|
||||
Pagination: PaginationDTO{
|
||||
Total: total,
|
||||
Page: page,
|
||||
PageSize: pageSize,
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,83 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
|
||||
)
|
||||
|
||||
// SnoozeAlarmRequest 定义了忽略告警的请求体
|
||||
type SnoozeAlarmRequest struct {
|
||||
DurationMinutes uint `json:"duration_minutes" validate:"required,min=1"` // 忽略时长,单位分钟
|
||||
}
|
||||
|
||||
// ListActiveAlarmRequest 定义了获取活跃告警列表的请求参数
|
||||
type ListActiveAlarmRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
SourceType *models.AlarmSourceType `json:"source_type" query:"source_type"` // 按告警来源类型过滤
|
||||
SourceID *uint `json:"source_id" query:"source_id"` // 按告警来源ID过滤
|
||||
Level *models.SeverityLevel `json:"level" query:"level"` // 按告警严重性等级过滤
|
||||
IsIgnored *bool `json:"is_ignored" query:"is_ignored"` // 按是否被忽略过滤
|
||||
TriggerTime *time.Time `json:"trigger_time" query:"trigger_time"` // 告警触发时间范围 - 开始时间
|
||||
EndTime *time.Time `json:"end_time" query:"end_time"` // 告警触发时间范围 - 结束时间
|
||||
OrderBy string `json:"order_by" query:"order_by"` // 排序字段,例如 "trigger_time DESC"
|
||||
}
|
||||
|
||||
// ActiveAlarmDTO 是用于API响应的活跃告警结构
|
||||
type ActiveAlarmDTO struct {
|
||||
ID uint `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
SourceType models.AlarmSourceType `json:"source_type"`
|
||||
SourceID uint `json:"source_id"`
|
||||
AlarmCode models.AlarmCode `json:"alarm_code"`
|
||||
AlarmSummary string `json:"alarm_summary"`
|
||||
Level models.SeverityLevel `json:"level"`
|
||||
AlarmDetails string `json:"alarm_details"`
|
||||
TriggerTime time.Time `json:"trigger_time"`
|
||||
IsIgnored bool `json:"is_ignored"`
|
||||
IgnoredUntil *time.Time `json:"ignored_until"`
|
||||
LastNotifiedAt *time.Time `json:"last_notified_at"`
|
||||
}
|
||||
|
||||
// ListActiveAlarmResponse 是获取活跃告警列表的响应结构
|
||||
type ListActiveAlarmResponse struct {
|
||||
List []ActiveAlarmDTO `json:"list"`
|
||||
Pagination PaginationDTO `json:"pagination"`
|
||||
}
|
||||
|
||||
// ListHistoricalAlarmRequest 定义了获取历史告警列表的请求参数
|
||||
type ListHistoricalAlarmRequest struct {
|
||||
Page int `json:"page" query:"page"`
|
||||
PageSize int `json:"page_size" query:"page_size"`
|
||||
SourceType *models.AlarmSourceType `json:"source_type" query:"source_type"` // 按告警来源类型过滤
|
||||
SourceID *uint `json:"source_id" query:"source_id"` // 按告警来源ID过滤
|
||||
Level *models.SeverityLevel `json:"level" query:"level"` // 按告警严重性等级过滤
|
||||
TriggerTimeStart *time.Time `json:"trigger_time_start" query:"trigger_time_start"` // 告警触发时间范围 - 开始时间
|
||||
TriggerTimeEnd *time.Time `json:"trigger_time_end" query:"trigger_time_end"` // 告警触发时间范围 - 结束时间
|
||||
ResolveTimeStart *time.Time `json:"resolve_time_start" query:"resolve_time_start"` // 告警解决时间范围 - 开始时间
|
||||
ResolveTimeEnd *time.Time `json:"resolve_time_end" query:"resolve_time_end"` // 告警解决时间范围 - 结束时间
|
||||
OrderBy string `json:"order_by" query:"order_by"` // 排序字段,例如 "trigger_time DESC"
|
||||
}
|
||||
|
||||
// HistoricalAlarmDTO 是用于API响应的历史告警结构
|
||||
type HistoricalAlarmDTO struct {
|
||||
ID uint `json:"id"`
|
||||
SourceType models.AlarmSourceType `json:"source_type"`
|
||||
SourceID uint `json:"source_id"`
|
||||
AlarmCode models.AlarmCode `json:"alarm_code"`
|
||||
AlarmSummary string `json:"alarm_summary"`
|
||||
Level models.SeverityLevel `json:"level"`
|
||||
AlarmDetails string `json:"alarm_details"`
|
||||
TriggerTime time.Time `json:"trigger_time"`
|
||||
ResolveTime time.Time `json:"resolve_time"`
|
||||
ResolveMethod string `json:"resolve_method"`
|
||||
ResolvedBy *uint `json:"resolved_by"`
|
||||
}
|
||||
|
||||
// ListHistoricalAlarmResponse 是获取历史告警列表的响应结构
|
||||
type ListHistoricalAlarmResponse struct {
|
||||
List []HistoricalAlarmDTO `json:"list"`
|
||||
Pagination PaginationDTO `json:"pagination"`
|
||||
}
|
||||
|
||||
10
internal/app/dto/dto.go
Normal file
10
internal/app/dto/dto.go
Normal file
@@ -0,0 +1,10 @@
|
||||
package dto
|
||||
|
||||
// --- General ---
|
||||
|
||||
// PaginationDTO 定义了分页信息的标准结构
|
||||
type PaginationDTO struct {
|
||||
Total int64 `json:"total"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"page_size"`
|
||||
}
|
||||
@@ -7,15 +7,6 @@ import (
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
|
||||
)
|
||||
|
||||
// --- General ---
|
||||
|
||||
// PaginationDTO 定义了分页信息的标准结构
|
||||
type PaginationDTO struct {
|
||||
Total int64 `json:"total"`
|
||||
Page int `json:"page"`
|
||||
PageSize int `json:"page_size"`
|
||||
}
|
||||
|
||||
// --- SensorData ---
|
||||
|
||||
// ListSensorDataRequest 定义了获取传感器数据列表的请求参数
|
||||
|
||||
Reference in New Issue
Block a user