增加两个批量查询接口

This commit is contained in:
2025-11-16 16:30:26 +08:00
parent bf747e22ce
commit bf1600b385
10 changed files with 1041 additions and 11 deletions

View File

@@ -179,6 +179,76 @@ func (t *ThresholdAlarmController) ListHistoricalAlarms(ctx echo.Context) error
return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "成功获取历史告警列表", resp, actionType, "成功获取历史告警列表", req)
}
// ListDeviceThresholdAlarms godoc
// @Summary 批量查询设备阈值告警
// @Description 根据过滤条件和分页参数查询设备阈值告警列表
// @Tags 告警管理
// @Security BearerAuth
// @Accept json
// @Produce json
// @Param query query dto.ListDeviceThresholdAlarmRequest true "查询参数"
// @Success 200 {object} controller.Response{data=dto.ListDeviceThresholdAlarmResponse} "成功获取设备阈值告警列表"
// @Router /api/v1/alarm/threshold/device [get]
func (t *ThresholdAlarmController) ListDeviceThresholdAlarms(ctx echo.Context) error {
reqCtx, logger := logs.Trace(ctx.Request().Context(), t.ctx, "ListDeviceThresholdAlarms")
const actionType = "批量查询设备阈值告警"
var req dto.ListDeviceThresholdAlarmRequest
if err := ctx.Bind(&req); err != nil {
logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的请求参数: "+err.Error(), actionType, "请求参数绑定失败", nil)
}
resp, err := t.thresholdAlarmService.ListDeviceThresholdAlarms(reqCtx, &req)
if err != nil {
// 捕获 ErrInvalidPagination 错误,并返回 Bad Request
if errors.Is(err, repository.ErrInvalidPagination) {
logger.Warnf("%s: 无效的分页参数: %v", actionType, err)
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的分页参数: "+err.Error(), actionType, "无效分页参数", req)
}
logger.Errorf("%s: 服务层查询设备阈值告警失败: %v", actionType, err)
return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "查询设备阈值告警失败: "+err.Error(), actionType, "服务层查询设备阈值告警失败", req)
}
logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(resp.List), resp.Pagination.Total)
return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "成功获取设备阈值告警列表", resp, actionType, "成功获取设备阈值告警列表", req)
}
// ListAreaThresholdAlarms godoc
// @Summary 批量查询区域阈值告警
// @Description 根据过滤条件和分页参数查询区域阈值告警列表
// @Tags 告警管理
// @Security BearerAuth
// @Accept json
// @Produce json
// @Param query query dto.ListAreaThresholdAlarmRequest true "查询参数"
// @Success 200 {object} controller.Response{data=dto.ListAreaThresholdAlarmResponse} "成功获取区域阈值告警列表"
// @Router /api/v1/alarm/threshold/area [get]
func (t *ThresholdAlarmController) ListAreaThresholdAlarms(ctx echo.Context) error {
reqCtx, logger := logs.Trace(ctx.Request().Context(), t.ctx, "ListAreaThresholdAlarms")
const actionType = "批量查询区域阈值告警"
var req dto.ListAreaThresholdAlarmRequest
if err := ctx.Bind(&req); err != nil {
logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的请求参数: "+err.Error(), actionType, "请求参数绑定失败", nil)
}
resp, err := t.thresholdAlarmService.ListAreaThresholdAlarms(reqCtx, &req)
if err != nil {
// 捕获 ErrInvalidPagination 错误,并返回 Bad Request
if errors.Is(err, repository.ErrInvalidPagination) {
logger.Warnf("%s: 无效的分页参数: %v", actionType, err)
return controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的分页参数: "+err.Error(), actionType, "无效分页参数", req)
}
logger.Errorf("%s: 服务层查询区域阈值告警失败: %v", actionType, err)
return controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "查询区域阈值告警失败: "+err.Error(), actionType, "服务层查询区域阈值告警失败", req)
}
logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(resp.List), resp.Pagination.Total)
return controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "成功获取区域阈值告警列表", resp, actionType, "成功获取区域阈值告警列表", req)
}
// CreateDeviceThresholdAlarm godoc
// @Summary 创建设备阈值告警
// @Description 为单个设备创建一条新的阈值告警规则