Files
pig-farm-controller/internal/app/service/monitor_service.go
2025-10-18 16:04:54 +08:00

77 lines
3.7 KiB
Go

package service
import (
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
"git.huangwc.com/pig/pig-farm-controller/internal/infra/repository"
)
// MonitorService 定义了监控相关的业务逻辑服务
type MonitorService struct {
sensorDataRepo repository.SensorDataRepository
deviceCommandLogRepo repository.DeviceCommandLogRepository
executionLogRepo repository.ExecutionLogRepository
pendingCollectionRepo repository.PendingCollectionRepository
userActionLogRepo repository.UserActionLogRepository
rawMaterialRepo repository.RawMaterialRepository
// 在这里可以添加其他超表模型的仓库依赖
}
// NewMonitorService 创建一个新的 MonitorService 实例
func NewMonitorService(
sensorDataRepo repository.SensorDataRepository,
deviceCommandLogRepo repository.DeviceCommandLogRepository,
executionLogRepo repository.ExecutionLogRepository,
pendingCollectionRepo repository.PendingCollectionRepository,
userActionLogRepo repository.UserActionLogRepository,
rawMaterialRepo repository.RawMaterialRepository,
) *MonitorService {
return &MonitorService{
sensorDataRepo: sensorDataRepo,
deviceCommandLogRepo: deviceCommandLogRepo,
executionLogRepo: executionLogRepo,
pendingCollectionRepo: pendingCollectionRepo,
userActionLogRepo: userActionLogRepo,
rawMaterialRepo: rawMaterialRepo,
}
}
// ListSensorData 负责处理查询传感器数据列表的业务逻辑
func (s *MonitorService) ListSensorData(opts repository.SensorDataListOptions, page, pageSize int) ([]models.SensorData, int64, error) {
return s.sensorDataRepo.List(opts, page, pageSize)
}
// ListDeviceCommandLogs 负责处理查询设备命令日志列表的业务逻辑
func (s *MonitorService) ListDeviceCommandLogs(opts repository.DeviceCommandLogListOptions, page, pageSize int) ([]models.DeviceCommandLog, int64, error) {
return s.deviceCommandLogRepo.List(opts, page, pageSize)
}
// ListPlanExecutionLogs 负责处理查询计划执行日志列表的业务逻辑
func (s *MonitorService) ListPlanExecutionLogs(opts repository.PlanExecutionLogListOptions, page, pageSize int) ([]models.PlanExecutionLog, int64, error) {
return s.executionLogRepo.ListPlanExecutionLogs(opts, page, pageSize)
}
// ListTaskExecutionLogs 负责处理查询任务执行日志列表的业务逻辑
func (s *MonitorService) ListTaskExecutionLogs(opts repository.TaskExecutionLogListOptions, page, pageSize int) ([]models.TaskExecutionLog, int64, error) {
return s.executionLogRepo.ListTaskExecutionLogs(opts, page, pageSize)
}
// ListPendingCollections 负责处理查询待采集请求列表的业务逻辑
func (s *MonitorService) ListPendingCollections(opts repository.PendingCollectionListOptions, page, pageSize int) ([]models.PendingCollection, int64, error) {
return s.pendingCollectionRepo.List(opts, page, pageSize)
}
// ListUserActionLogs 负责处理查询用户操作日志列表的业务逻辑
func (s *MonitorService) ListUserActionLogs(opts repository.UserActionLogListOptions, page, pageSize int) ([]models.UserActionLog, int64, error) {
return s.userActionLogRepo.List(opts, page, pageSize)
}
// ListRawMaterialPurchases 负责处理查询原料采购记录列表的业务逻辑
func (s *MonitorService) ListRawMaterialPurchases(opts repository.RawMaterialPurchaseListOptions, page, pageSize int) ([]models.RawMaterialPurchase, int64, error) {
return s.rawMaterialRepo.ListRawMaterialPurchases(opts, page, pageSize)
}
// ListRawMaterialStockLogs 负责处理查询原料库存日志列表的业务逻辑
func (s *MonitorService) ListRawMaterialStockLogs(opts repository.RawMaterialStockLogListOptions, page, pageSize int) ([]models.RawMaterialStockLog, int64, error) {
return s.rawMaterialRepo.ListRawMaterialStockLogs(opts, page, pageSize)
}