定义病猪子服务
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/repository"
|
||||
)
|
||||
|
||||
// --- 业务错误定义 ---
|
||||
@@ -56,3 +57,34 @@ type PigBatchService interface {
|
||||
|
||||
UpdatePigBatchQuantity(operatorID uint, batchID uint, changeType models.LogChangeType, changeAmount int, changeReason string, happenedAt time.Time) error
|
||||
}
|
||||
|
||||
// pigBatchService 是 PigBatchService 接口的具体实现。
|
||||
// 它作为猪群领域的主服务,封装了所有业务逻辑。
|
||||
type pigBatchService struct {
|
||||
pigBatchRepo repository.PigBatchRepository // 猪批次仓库
|
||||
pigBatchLogRepo repository.PigBatchLogRepository // 猪批次日志仓库
|
||||
uow repository.UnitOfWork // 工作单元,用于管理事务
|
||||
transferSvc PigPenTransferManager // 调栏子服务
|
||||
tradeSvc PigTradeManager // 交易子服务
|
||||
sickSvc SickPigManager // 病猪子服务
|
||||
}
|
||||
|
||||
// NewPigBatchService 是 pigBatchService 的构造函数。
|
||||
// 它通过依赖注入的方式,创建并返回一个 PigBatchService 接口的实例。
|
||||
func NewPigBatchService(
|
||||
pigBatchRepo repository.PigBatchRepository,
|
||||
pigBatchLogRepo repository.PigBatchLogRepository,
|
||||
uow repository.UnitOfWork,
|
||||
transferSvc PigPenTransferManager,
|
||||
tradeSvc PigTradeManager,
|
||||
sickSvc SickPigManager,
|
||||
) PigBatchService {
|
||||
return &pigBatchService{
|
||||
pigBatchRepo: pigBatchRepo,
|
||||
pigBatchLogRepo: pigBatchLogRepo,
|
||||
uow: uow,
|
||||
transferSvc: transferSvc,
|
||||
tradeSvc: tradeSvc,
|
||||
sickSvc: sickSvc,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,40 +6,11 @@ import (
|
||||
"time"
|
||||
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/models"
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/repository"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// --- 领域服务实现 ---
|
||||
|
||||
// pigBatchService 是 PigBatchService 接口的具体实现。
|
||||
// 它作为猪群领域的主服务,封装了所有业务逻辑。
|
||||
type pigBatchService struct {
|
||||
pigBatchRepo repository.PigBatchRepository // 猪批次仓库
|
||||
pigBatchLogRepo repository.PigBatchLogRepository // 猪批次日志仓库
|
||||
uow repository.UnitOfWork // 工作单元,用于管理事务
|
||||
transferSvc PigPenTransferManager // 调栏子服务
|
||||
tradeSvc PigTradeManager // 交易子服务
|
||||
}
|
||||
|
||||
// NewPigBatchService 是 pigBatchService 的构造函数。
|
||||
// 它通过依赖注入的方式,创建并返回一个 PigBatchService 接口的实例。
|
||||
func NewPigBatchService(
|
||||
pigBatchRepo repository.PigBatchRepository,
|
||||
pigBatchLogRepo repository.PigBatchLogRepository,
|
||||
uow repository.UnitOfWork,
|
||||
transferSvc PigPenTransferManager,
|
||||
tradeSvc PigTradeManager,
|
||||
) PigBatchService {
|
||||
return &pigBatchService{
|
||||
pigBatchRepo: pigBatchRepo,
|
||||
pigBatchLogRepo: pigBatchLogRepo,
|
||||
uow: uow,
|
||||
transferSvc: transferSvc,
|
||||
tradeSvc: tradeSvc,
|
||||
}
|
||||
}
|
||||
|
||||
// CreatePigBatch 实现了创建猪批次的逻辑,并同时创建初始批次日志。
|
||||
func (s *pigBatchService) CreatePigBatch(operatorID uint, batch *models.PigBatch) (*models.PigBatch, error) {
|
||||
// 业务规则可以在这里添加,例如检查批次号是否唯一等
|
||||
|
||||
@@ -1 +1,28 @@
|
||||
package pig
|
||||
|
||||
import (
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/repository"
|
||||
)
|
||||
|
||||
// SickPigManager 定义了与病猪管理相关的操作接口。
|
||||
// 这是一个领域服务,负责协调病猪记录、用药等业务逻辑。
|
||||
type SickPigManager interface {
|
||||
}
|
||||
|
||||
// sickPigManager 是 SickPigManager 接口的具体实现。
|
||||
// 它依赖于仓库接口来执行数据持久化操作。
|
||||
type sickPigManager struct {
|
||||
sickLogRepo repository.PigSickLogRepository
|
||||
medicationLogRepo repository.MedicationLogRepository
|
||||
}
|
||||
|
||||
// NewSickPigManager 是 sickPigManager 的构造函数。
|
||||
func NewSickPigManager(
|
||||
sickLogRepo repository.PigSickLogRepository,
|
||||
medicationLogRepo repository.MedicationLogRepository,
|
||||
) SickPigManager {
|
||||
return &sickPigManager{
|
||||
sickLogRepo: sickLogRepo,
|
||||
medicationLogRepo: medicationLogRepo,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user