实现controller
This commit is contained in:
@@ -839,3 +839,50 @@ func (c *Controller) ListPigSales(ctx *gin.Context) {
|
||||
c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
|
||||
controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "获取猪只售卖记录成功", resp, actionType, "获取猪只售卖记录成功", req)
|
||||
}
|
||||
|
||||
// ListNotifications godoc
|
||||
// @Summary 批量查询通知
|
||||
// @Description 根据提供的过滤条件,分页获取通知列表
|
||||
// @Tags 数据监控
|
||||
// @Security BearerAuth
|
||||
// @Produce json
|
||||
// @Param query query dto.ListNotificationRequest true "查询参数"
|
||||
// @Success 200 {object} controller.Response{data=dto.ListNotificationResponse}
|
||||
// @Router /api/v1/monitor/notifications [get]
|
||||
func (c *Controller) ListNotifications(ctx *gin.Context) {
|
||||
const actionType = "批量查询通知"
|
||||
|
||||
var req dto.ListNotificationRequest
|
||||
if err := ctx.ShouldBindQuery(&req); err != nil {
|
||||
c.logger.Errorf("%s: 参数绑定失败: %v", actionType, err)
|
||||
controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的查询参数: "+err.Error(), actionType, "参数绑定失败", req)
|
||||
return
|
||||
}
|
||||
|
||||
opts := repository.NotificationListOptions{
|
||||
UserID: req.UserID,
|
||||
NotifierType: req.NotifierType,
|
||||
Level: req.Level,
|
||||
StartTime: req.StartTime,
|
||||
EndTime: req.EndTime,
|
||||
OrderBy: req.OrderBy,
|
||||
Status: req.Status,
|
||||
}
|
||||
|
||||
data, total, err := c.monitorService.ListNotifications(opts, req.Page, req.PageSize)
|
||||
if err != nil {
|
||||
if errors.Is(err, repository.ErrInvalidPagination) {
|
||||
c.logger.Warnf("%s: 无效的分页参数: %v", actionType, err)
|
||||
controller.SendErrorWithAudit(ctx, controller.CodeBadRequest, "无效的分页参数: "+err.Error(), actionType, "无效分页参数", req)
|
||||
return
|
||||
}
|
||||
|
||||
c.logger.Errorf("%s: 服务层查询失败: %v", actionType, err)
|
||||
controller.SendErrorWithAudit(ctx, controller.CodeInternalError, "批量查询通知失败: "+err.Error(), actionType, "服务层查询失败", req)
|
||||
return
|
||||
}
|
||||
|
||||
resp := dto.NewListNotificationResponse(data, total, req.Page, req.PageSize)
|
||||
c.logger.Infof("%s: 成功, 获取到 %d 条记录, 总计 %d 条", actionType, len(data), total)
|
||||
controller.SendSuccessWithAudit(ctx, controller.CodeSuccess, "批量查询通知成功", resp, actionType, "批量查询通知成功", req)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user