issue_22 #41
@@ -24,6 +24,7 @@ type MonitorService interface {
 | 
				
			|||||||
	ListPigSickLogs(opts repository.PigSickLogListOptions, page, pageSize int) ([]models.PigSickLog, int64, error)
 | 
						ListPigSickLogs(opts repository.PigSickLogListOptions, page, pageSize int) ([]models.PigSickLog, int64, error)
 | 
				
			||||||
	ListPigPurchases(opts repository.PigPurchaseListOptions, page, pageSize int) ([]models.PigPurchase, int64, error)
 | 
						ListPigPurchases(opts repository.PigPurchaseListOptions, page, pageSize int) ([]models.PigPurchase, int64, error)
 | 
				
			||||||
	ListPigSales(opts repository.PigSaleListOptions, page, pageSize int) ([]models.PigSale, int64, error)
 | 
						ListPigSales(opts repository.PigSaleListOptions, page, pageSize int) ([]models.PigSale, int64, error)
 | 
				
			||||||
 | 
						ListNotifications(opts repository.NotificationListOptions, page, pageSize int) ([]models.Notification, int64, error)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// monitorService 是 MonitorService 接口的具体实现
 | 
					// monitorService 是 MonitorService 接口的具体实现
 | 
				
			||||||
@@ -40,6 +41,7 @@ type monitorService struct {
 | 
				
			|||||||
	pigTransferLogRepo    repository.PigTransferLogRepository
 | 
						pigTransferLogRepo    repository.PigTransferLogRepository
 | 
				
			||||||
	pigSickLogRepo        repository.PigSickLogRepository
 | 
						pigSickLogRepo        repository.PigSickLogRepository
 | 
				
			||||||
	pigTradeRepo          repository.PigTradeRepository
 | 
						pigTradeRepo          repository.PigTradeRepository
 | 
				
			||||||
 | 
						notificationRepo      repository.NotificationRepository
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// NewMonitorService 创建一个新的 MonitorService 实例
 | 
					// NewMonitorService 创建一个新的 MonitorService 实例
 | 
				
			||||||
@@ -56,6 +58,7 @@ func NewMonitorService(
 | 
				
			|||||||
	pigTransferLogRepo repository.PigTransferLogRepository,
 | 
						pigTransferLogRepo repository.PigTransferLogRepository,
 | 
				
			||||||
	pigSickLogRepo repository.PigSickLogRepository,
 | 
						pigSickLogRepo repository.PigSickLogRepository,
 | 
				
			||||||
	pigTradeRepo repository.PigTradeRepository,
 | 
						pigTradeRepo repository.PigTradeRepository,
 | 
				
			||||||
 | 
						notificationRepo repository.NotificationRepository,
 | 
				
			||||||
) MonitorService {
 | 
					) MonitorService {
 | 
				
			||||||
	return &monitorService{
 | 
						return &monitorService{
 | 
				
			||||||
		sensorDataRepo:        sensorDataRepo,
 | 
							sensorDataRepo:        sensorDataRepo,
 | 
				
			||||||
@@ -70,6 +73,7 @@ func NewMonitorService(
 | 
				
			|||||||
		pigTransferLogRepo:    pigTransferLogRepo,
 | 
							pigTransferLogRepo:    pigTransferLogRepo,
 | 
				
			||||||
		pigSickLogRepo:        pigSickLogRepo,
 | 
							pigSickLogRepo:        pigSickLogRepo,
 | 
				
			||||||
		pigTradeRepo:          pigTradeRepo,
 | 
							pigTradeRepo:          pigTradeRepo,
 | 
				
			||||||
 | 
							notificationRepo:      notificationRepo,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -157,3 +161,8 @@ func (s *monitorService) ListPigPurchases(opts repository.PigPurchaseListOptions
 | 
				
			|||||||
func (s *monitorService) ListPigSales(opts repository.PigSaleListOptions, page, pageSize int) ([]models.PigSale, int64, error) {
 | 
					func (s *monitorService) ListPigSales(opts repository.PigSaleListOptions, page, pageSize int) ([]models.PigSale, int64, error) {
 | 
				
			||||||
	return s.pigTradeRepo.ListPigSales(opts, page, pageSize)
 | 
						return s.pigTradeRepo.ListPigSales(opts, page, pageSize)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// ListNotifications 负责处理查询通知列表的业务逻辑
 | 
				
			||||||
 | 
					func (s *monitorService) ListNotifications(opts repository.NotificationListOptions, page, pageSize int) ([]models.Notification, int64, error) {
 | 
				
			||||||
 | 
						return s.notificationRepo.List(opts, page, pageSize)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,6 +5,7 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
 | 
						"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
 | 
				
			||||||
	"git.huangwc.com/pig/pig-farm-controller/internal/infra/notify"
 | 
						"git.huangwc.com/pig/pig-farm-controller/internal/infra/notify"
 | 
				
			||||||
 | 
						"go.uber.org/zap/zapcore"
 | 
				
			||||||
	"gorm.io/gorm"
 | 
						"gorm.io/gorm"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -13,6 +14,7 @@ type NotificationListOptions struct {
 | 
				
			|||||||
	UserID       *uint                // 按用户ID过滤
 | 
						UserID       *uint                // 按用户ID过滤
 | 
				
			||||||
	NotifierType *notify.NotifierType // 按通知器类型过滤
 | 
						NotifierType *notify.NotifierType // 按通知器类型过滤
 | 
				
			||||||
	Status       *string              // 按通知状态过滤 (例如:"success", "failed", "pending")
 | 
						Status       *string              // 按通知状态过滤 (例如:"success", "failed", "pending")
 | 
				
			||||||
 | 
						Level        *zapcore.Level       // 按通知等级过滤 (例如:"info", "warning", "error")
 | 
				
			||||||
	StartTime    *time.Time           // 通知内容生成时间范围 - 开始时间 (对应 AlarmTimestamp)
 | 
						StartTime    *time.Time           // 通知内容生成时间范围 - 开始时间 (对应 AlarmTimestamp)
 | 
				
			||||||
	EndTime      *time.Time           // 通知内容生成时间范围 - 结束时间 (对应 AlarmTimestamp)
 | 
						EndTime      *time.Time           // 通知内容生成时间范围 - 结束时间 (对应 AlarmTimestamp)
 | 
				
			||||||
	OrderBy      string               // 排序字段,例如 "alarm_timestamp DESC"
 | 
						OrderBy      string               // 排序字段,例如 "alarm_timestamp DESC"
 | 
				
			||||||
@@ -79,6 +81,9 @@ func (r *gormNotificationRepository) List(opts NotificationListOptions, page, pa
 | 
				
			|||||||
	if opts.Status != nil {
 | 
						if opts.Status != nil {
 | 
				
			||||||
		query = query.Where("status = ?", *opts.Status)
 | 
							query = query.Where("status = ?", *opts.Status)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						if opts.Level != nil {
 | 
				
			||||||
 | 
							query = query.Where("level = ?", opts.Level.String())
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	if opts.StartTime != nil {
 | 
						if opts.StartTime != nil {
 | 
				
			||||||
		query = query.Where("alarm_timestamp >= ?", *opts.StartTime)
 | 
							query = query.Where("alarm_timestamp >= ?", *opts.StartTime)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user