160 lines
		
	
	
		
			9.2 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			160 lines
		
	
	
		
			9.2 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 interface {
 | 
						|
	ListSensorData(opts repository.SensorDataListOptions, page, pageSize int) ([]models.SensorData, int64, error)
 | 
						|
	ListDeviceCommandLogs(opts repository.DeviceCommandLogListOptions, page, pageSize int) ([]models.DeviceCommandLog, int64, error)
 | 
						|
	ListPlanExecutionLogs(opts repository.PlanExecutionLogListOptions, page, pageSize int) ([]models.PlanExecutionLog, int64, error)
 | 
						|
	ListTaskExecutionLogs(opts repository.TaskExecutionLogListOptions, page, pageSize int) ([]models.TaskExecutionLog, int64, error)
 | 
						|
	ListPendingCollections(opts repository.PendingCollectionListOptions, page, pageSize int) ([]models.PendingCollection, int64, error)
 | 
						|
	ListUserActionLogs(opts repository.UserActionLogListOptions, page, pageSize int) ([]models.UserActionLog, int64, error)
 | 
						|
	ListRawMaterialPurchases(opts repository.RawMaterialPurchaseListOptions, page, pageSize int) ([]models.RawMaterialPurchase, int64, error)
 | 
						|
	ListRawMaterialStockLogs(opts repository.RawMaterialStockLogListOptions, page, pageSize int) ([]models.RawMaterialStockLog, int64, error)
 | 
						|
	ListFeedUsageRecords(opts repository.FeedUsageRecordListOptions, page, pageSize int) ([]models.FeedUsageRecord, int64, error)
 | 
						|
	ListMedicationLogs(opts repository.MedicationLogListOptions, page, pageSize int) ([]models.MedicationLog, int64, error)
 | 
						|
	ListPigBatchLogs(opts repository.PigBatchLogListOptions, page, pageSize int) ([]models.PigBatchLog, int64, error)
 | 
						|
	ListWeighingBatches(opts repository.WeighingBatchListOptions, page, pageSize int) ([]models.WeighingBatch, int64, error)
 | 
						|
	ListWeighingRecords(opts repository.WeighingRecordListOptions, page, pageSize int) ([]models.WeighingRecord, int64, error)
 | 
						|
	ListPigTransferLogs(opts repository.PigTransferLogListOptions, page, pageSize int) ([]models.PigTransferLog, int64, error)
 | 
						|
	ListPigSickLogs(opts repository.PigSickLogListOptions, page, pageSize int) ([]models.PigSickLog, int64, error)
 | 
						|
	ListPigPurchases(opts repository.PigPurchaseListOptions, page, pageSize int) ([]models.PigPurchase, int64, error)
 | 
						|
	ListPigSales(opts repository.PigSaleListOptions, page, pageSize int) ([]models.PigSale, int64, error)
 | 
						|
}
 | 
						|
 | 
						|
// monitorService 是 MonitorService 接口的具体实现
 | 
						|
type monitorService struct {
 | 
						|
	sensorDataRepo        repository.SensorDataRepository
 | 
						|
	deviceCommandLogRepo  repository.DeviceCommandLogRepository
 | 
						|
	executionLogRepo      repository.ExecutionLogRepository
 | 
						|
	pendingCollectionRepo repository.PendingCollectionRepository
 | 
						|
	userActionLogRepo     repository.UserActionLogRepository
 | 
						|
	rawMaterialRepo       repository.RawMaterialRepository
 | 
						|
	medicationRepo        repository.MedicationLogRepository
 | 
						|
	pigBatchRepo          repository.PigBatchRepository
 | 
						|
	pigBatchLogRepo       repository.PigBatchLogRepository
 | 
						|
	pigTransferLogRepo    repository.PigTransferLogRepository
 | 
						|
	pigSickLogRepo        repository.PigSickLogRepository
 | 
						|
	pigTradeRepo          repository.PigTradeRepository
 | 
						|
}
 | 
						|
 | 
						|
// NewMonitorService 创建一个新的 MonitorService 实例
 | 
						|
func NewMonitorService(
 | 
						|
	sensorDataRepo repository.SensorDataRepository,
 | 
						|
	deviceCommandLogRepo repository.DeviceCommandLogRepository,
 | 
						|
	executionLogRepo repository.ExecutionLogRepository,
 | 
						|
	pendingCollectionRepo repository.PendingCollectionRepository,
 | 
						|
	userActionLogRepo repository.UserActionLogRepository,
 | 
						|
	rawMaterialRepo repository.RawMaterialRepository,
 | 
						|
	medicationRepo repository.MedicationLogRepository,
 | 
						|
	pigBatchRepo repository.PigBatchRepository,
 | 
						|
	pigBatchLogRepo repository.PigBatchLogRepository,
 | 
						|
	pigTransferLogRepo repository.PigTransferLogRepository,
 | 
						|
	pigSickLogRepo repository.PigSickLogRepository,
 | 
						|
	pigTradeRepo repository.PigTradeRepository,
 | 
						|
) MonitorService {
 | 
						|
	return &monitorService{
 | 
						|
		sensorDataRepo:        sensorDataRepo,
 | 
						|
		deviceCommandLogRepo:  deviceCommandLogRepo,
 | 
						|
		executionLogRepo:      executionLogRepo,
 | 
						|
		pendingCollectionRepo: pendingCollectionRepo,
 | 
						|
		userActionLogRepo:     userActionLogRepo,
 | 
						|
		rawMaterialRepo:       rawMaterialRepo,
 | 
						|
		medicationRepo:        medicationRepo,
 | 
						|
		pigBatchRepo:          pigBatchRepo,
 | 
						|
		pigBatchLogRepo:       pigBatchLogRepo,
 | 
						|
		pigTransferLogRepo:    pigTransferLogRepo,
 | 
						|
		pigSickLogRepo:        pigSickLogRepo,
 | 
						|
		pigTradeRepo:          pigTradeRepo,
 | 
						|
	}
 | 
						|
}
 | 
						|
 | 
						|
// 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)
 | 
						|
}
 | 
						|
 | 
						|
// ListFeedUsageRecords 负责处理查询饲料使用记录列表的业务逻辑
 | 
						|
func (s *monitorService) ListFeedUsageRecords(opts repository.FeedUsageRecordListOptions, page, pageSize int) ([]models.FeedUsageRecord, int64, error) {
 | 
						|
	return s.rawMaterialRepo.ListFeedUsageRecords(opts, page, pageSize)
 | 
						|
}
 | 
						|
 | 
						|
// ListMedicationLogs 负责处理查询用药记录列表的业务逻辑
 | 
						|
func (s *monitorService) ListMedicationLogs(opts repository.MedicationLogListOptions, page, pageSize int) ([]models.MedicationLog, int64, error) {
 | 
						|
	return s.medicationRepo.ListMedicationLogs(opts, page, pageSize)
 | 
						|
}
 | 
						|
 | 
						|
// ListPigBatchLogs 负责处理查询猪批次日志列表的业务逻辑
 | 
						|
func (s *monitorService) ListPigBatchLogs(opts repository.PigBatchLogListOptions, page, pageSize int) ([]models.PigBatchLog, int64, error) {
 | 
						|
	return s.pigBatchLogRepo.List(opts, page, pageSize)
 | 
						|
}
 | 
						|
 | 
						|
// ListWeighingBatches 负责处理查询批次称重记录列表的业务逻辑
 | 
						|
func (s *monitorService) ListWeighingBatches(opts repository.WeighingBatchListOptions, page, pageSize int) ([]models.WeighingBatch, int64, error) {
 | 
						|
	return s.pigBatchRepo.ListWeighingBatches(opts, page, pageSize)
 | 
						|
}
 | 
						|
 | 
						|
// ListWeighingRecords 负责处理查询单次称重记录列表的业务逻辑
 | 
						|
func (s *monitorService) ListWeighingRecords(opts repository.WeighingRecordListOptions, page, pageSize int) ([]models.WeighingRecord, int64, error) {
 | 
						|
	return s.pigBatchRepo.ListWeighingRecords(opts, page, pageSize)
 | 
						|
}
 | 
						|
 | 
						|
// ListPigTransferLogs 负责处理查询猪只迁移日志列表的业务逻辑
 | 
						|
func (s *monitorService) ListPigTransferLogs(opts repository.PigTransferLogListOptions, page, pageSize int) ([]models.PigTransferLog, int64, error) {
 | 
						|
	return s.pigTransferLogRepo.ListPigTransferLogs(opts, page, pageSize)
 | 
						|
}
 | 
						|
 | 
						|
// ListPigSickLogs 负责处理查询病猪日志列表的业务逻辑
 | 
						|
func (s *monitorService) ListPigSickLogs(opts repository.PigSickLogListOptions, page, pageSize int) ([]models.PigSickLog, int64, error) {
 | 
						|
	return s.pigSickLogRepo.ListPigSickLogs(opts, page, pageSize)
 | 
						|
}
 | 
						|
 | 
						|
// ListPigPurchases 负责处理查询猪只采购记录列表的业务逻辑
 | 
						|
func (s *monitorService) ListPigPurchases(opts repository.PigPurchaseListOptions, page, pageSize int) ([]models.PigPurchase, int64, error) {
 | 
						|
	return s.pigTradeRepo.ListPigPurchases(opts, page, pageSize)
 | 
						|
}
 | 
						|
 | 
						|
// ListPigSales 负责处理查询猪只销售记录列表的业务逻辑
 | 
						|
func (s *monitorService) ListPigSales(opts repository.PigSaleListOptions, page, pageSize int) ([]models.PigSale, int64, error) {
 | 
						|
	return s.pigTradeRepo.ListPigSales(opts, page, pageSize)
 | 
						|
}
 |