实现忽略告警和取消忽略告警接口及功能

This commit is contained in:
2025-11-09 22:34:05 +08:00
parent 84fe20396b
commit b94aa6137c
11 changed files with 292 additions and 16 deletions

View File

@@ -19,6 +19,7 @@ import (
"time"
_ "git.huangwc.com/pig/pig-farm-controller/docs" // 引入 swag 生成的 docs
"git.huangwc.com/pig/pig-farm-controller/internal/app/controller/alarm"
"git.huangwc.com/pig/pig-farm-controller/internal/app/controller/device"
"git.huangwc.com/pig/pig-farm-controller/internal/app/controller/health"
"git.huangwc.com/pig/pig-farm-controller/internal/app/controller/management"
@@ -53,6 +54,7 @@ type API struct {
pigBatchController *management.PigBatchController // 猪群控制器实例
monitorController *monitor.Controller // 数据监控控制器实例
healthController *health.Controller // 健康检查控制器实例
alarmController *alarm.ThresholdAlarmController // 阈值告警控制器
listenHandler webhook.ListenHandler // 设备上行事件监听器
analysisTaskManager *domain_plan.AnalysisPlanTaskManager // 计划触发器管理器实例
}
@@ -69,6 +71,7 @@ func NewAPI(cfg config.ServerConfig,
planService service.PlanService,
userService service.UserService,
auditService service.AuditService,
alarmService service.ThresholdAlarmService,
tokenGenerator token.Generator,
listenHandler webhook.ListenHandler,
) *API {
@@ -106,6 +109,8 @@ func NewAPI(cfg config.ServerConfig,
monitorController: monitor.NewController(logs.AddCompName(baseCtx, "MonitorController"), monitorService),
// 在 NewAPI 中初始化健康检查控制器
healthController: health.NewController(logs.AddCompName(baseCtx, "HealthController")),
// 在 NewAPI 中初始化阈
alarmController: alarm.NewThresholdAlarmController(logs.AddCompName(baseCtx, "ThresholdAlarmController"), alarmService),
}
api.setupRoutes() // 设置所有路由

View File

@@ -187,6 +187,17 @@ func (a *API) setupRoutes() {
monitorGroup.GET("/notifications", a.monitorController.ListNotifications)
}
logger.Debug("数据监控相关接口注册成功 (需要认证和审计)")
// 告警相关路由组
alarmGroup := authGroup.Group("/alarm")
{
thresholdGroup := alarmGroup.Group("/thresholds")
{
thresholdGroup.POST("/:id/snooze", a.alarmController.SnoozeThresholdAlarm) // 忽略阈值告警
thresholdGroup.POST("/:id/cancel-snooze", a.alarmController.CancelSnoozeThresholdAlarm) // 取消忽略阈值告警
}
}
logger.Debug("告警相关接口注册成功 (需要认证和审计)")
}
logger.Debug("所有接口注册成功")