猪群领域其他方法映射到api
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/app/dto"
|
||||
domain_pig "git.huangwc.com/pig/pig-farm-controller/internal/domain/pig"
|
||||
"git.huangwc.com/pig/pig-farm-controller/internal/infra/logs"
|
||||
@@ -14,10 +16,30 @@ type PigBatchService interface {
|
||||
UpdatePigBatch(id uint, dto *dto.PigBatchUpdateDTO) (*dto.PigBatchResponseDTO, error)
|
||||
DeletePigBatch(id uint) error
|
||||
ListPigBatches(isActive *bool) ([]*dto.PigBatchResponseDTO, error)
|
||||
|
||||
// Pig Pen Management
|
||||
AssignEmptyPensToBatch(batchID uint, penIDs []uint, operatorID uint) error
|
||||
ReclassifyPenToNewBatch(fromBatchID uint, toBatchID uint, penID uint, operatorID uint, remarks string) error
|
||||
RemoveEmptyPenFromBatch(batchID uint, penID uint) error
|
||||
MovePigsIntoPen(batchID uint, toPenID uint, quantity int, operatorID uint, remarks string) error
|
||||
|
||||
// Trade Sub-service
|
||||
SellPigs(batchID uint, penID uint, quantity int, unitPrice float64, tatalPrice float64, traderName string, tradeDate time.Time, remarks string, operatorID uint) error
|
||||
BuyPigs(batchID uint, penID uint, quantity int, unitPrice float64, tatalPrice float64, traderName string, tradeDate time.Time, remarks string, operatorID uint) error
|
||||
|
||||
// Transfer Sub-service
|
||||
TransferPigsAcrossBatches(sourceBatchID uint, destBatchID uint, fromPenID uint, toPenID uint, quantity uint, operatorID uint, remarks string) error
|
||||
TransferPigsWithinBatch(batchID uint, fromPenID uint, toPenID uint, quantity uint, operatorID uint, remarks string) error
|
||||
|
||||
// Sick Pig Management
|
||||
RecordSickPigs(operatorID uint, batchID uint, penID uint, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error
|
||||
RecordSickPigRecovery(operatorID uint, batchID uint, penID uint, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error
|
||||
RecordSickPigDeath(operatorID uint, batchID uint, penID uint, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error
|
||||
RecordSickPigCull(operatorID uint, batchID uint, penID uint, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error
|
||||
|
||||
// Normal Pig Management
|
||||
RecordDeath(operatorID uint, batchID uint, penID uint, quantity int, happenedAt time.Time, remarks string) error
|
||||
RecordCull(operatorID uint, batchID uint, penID uint, quantity int, happenedAt time.Time, remarks string) error
|
||||
}
|
||||
|
||||
// pigBatchService 的实现现在依赖于领域服务接口。
|
||||
@@ -191,3 +213,103 @@ func (s *pigBatchService) MovePigsIntoPen(batchID uint, toPenID uint, quantity i
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SellPigs 委托给领域服务
|
||||
func (s *pigBatchService) SellPigs(batchID uint, penID uint, quantity int, unitPrice float64, tatalPrice float64, traderName string, tradeDate time.Time, remarks string, operatorID uint) error {
|
||||
err := s.domainService.SellPigs(batchID, penID, quantity, unitPrice, tatalPrice, traderName, tradeDate, remarks, operatorID)
|
||||
if err != nil {
|
||||
s.logger.Errorf("应用层: 卖猪失败, 批次ID: %d, 错误: %v", batchID, err)
|
||||
return MapDomainError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// BuyPigs 委托给领域服务
|
||||
func (s *pigBatchService) BuyPigs(batchID uint, penID uint, quantity int, unitPrice float64, tatalPrice float64, traderName string, tradeDate time.Time, remarks string, operatorID uint) error {
|
||||
err := s.domainService.BuyPigs(batchID, penID, quantity, unitPrice, tatalPrice, traderName, tradeDate, remarks, operatorID)
|
||||
if err != nil {
|
||||
s.logger.Errorf("应用层: 买猪失败, 批次ID: %d, 错误: %v", batchID, err)
|
||||
return MapDomainError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// TransferPigsAcrossBatches 委托给领域服务
|
||||
func (s *pigBatchService) TransferPigsAcrossBatches(sourceBatchID uint, destBatchID uint, fromPenID uint, toPenID uint, quantity uint, operatorID uint, remarks string) error {
|
||||
err := s.domainService.TransferPigsAcrossBatches(sourceBatchID, destBatchID, fromPenID, toPenID, quantity, operatorID, remarks)
|
||||
if err != nil {
|
||||
s.logger.Errorf("应用层: 跨群调栏失败, 源批次ID: %d, 错误: %v", sourceBatchID, err)
|
||||
return MapDomainError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// TransferPigsWithinBatch 委托给领域服务
|
||||
func (s *pigBatchService) TransferPigsWithinBatch(batchID uint, fromPenID uint, toPenID uint, quantity uint, operatorID uint, remarks string) error {
|
||||
err := s.domainService.TransferPigsWithinBatch(batchID, fromPenID, toPenID, quantity, operatorID, remarks)
|
||||
if err != nil {
|
||||
s.logger.Errorf("应用层: 群内调栏失败, 批次ID: %d, 错误: %v", batchID, err)
|
||||
return MapDomainError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RecordSickPigs 委托给领域服务
|
||||
func (s *pigBatchService) RecordSickPigs(operatorID uint, batchID uint, penID uint, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error {
|
||||
err := s.domainService.RecordSickPigs(operatorID, batchID, penID, quantity, treatmentLocation, happenedAt, remarks)
|
||||
if err != nil {
|
||||
s.logger.Errorf("应用层: 记录病猪事件失败, 批次ID: %d, 错误: %v", batchID, err)
|
||||
return MapDomainError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RecordSickPigRecovery 委托给领域服务
|
||||
func (s *pigBatchService) RecordSickPigRecovery(operatorID uint, batchID uint, penID uint, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error {
|
||||
err := s.domainService.RecordSickPigRecovery(operatorID, batchID, penID, quantity, treatmentLocation, happenedAt, remarks)
|
||||
if err != nil {
|
||||
s.logger.Errorf("应用层: 记录病猪康复事件失败, 批次ID: %d, 错误: %v", batchID, err)
|
||||
return MapDomainError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RecordSickPigDeath 委托给领域服务
|
||||
func (s *pigBatchService) RecordSickPigDeath(operatorID uint, batchID uint, penID uint, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error {
|
||||
err := s.domainService.RecordSickPigDeath(operatorID, batchID, penID, quantity, treatmentLocation, happenedAt, remarks)
|
||||
if err != nil {
|
||||
s.logger.Errorf("应用层: 记录病猪死亡事件失败, 批次ID: %d, 错误: %v", batchID, err)
|
||||
return MapDomainError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RecordSickPigCull 委托给领域服务
|
||||
func (s *pigBatchService) RecordSickPigCull(operatorID uint, batchID uint, penID uint, quantity int, treatmentLocation models.PigBatchSickPigTreatmentLocation, happenedAt time.Time, remarks string) error {
|
||||
err := s.domainService.RecordSickPigCull(operatorID, batchID, penID, quantity, treatmentLocation, happenedAt, remarks)
|
||||
if err != nil {
|
||||
s.logger.Errorf("应用层: 记录病猪淘汰事件失败, 批次ID: %d, 错误: %v", batchID, err)
|
||||
return MapDomainError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RecordDeath 委托给领域服务
|
||||
func (s *pigBatchService) RecordDeath(operatorID uint, batchID uint, penID uint, quantity int, happenedAt time.Time, remarks string) error {
|
||||
err := s.domainService.RecordDeath(operatorID, batchID, penID, quantity, happenedAt, remarks)
|
||||
if err != nil {
|
||||
s.logger.Errorf("应用层: 记录正常猪只死亡事件失败, 批次ID: %d, 错误: %v", batchID, err)
|
||||
return MapDomainError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RecordCull 委托给领域服务
|
||||
func (s *pigBatchService) RecordCull(operatorID uint, batchID uint, penID uint, quantity int, happenedAt time.Time, remarks string) error {
|
||||
err := s.domainService.RecordCull(operatorID, batchID, penID, quantity, happenedAt, remarks)
|
||||
if err != nil {
|
||||
s.logger.Errorf("应用层: 记录正常猪只淘汰事件失败, 批次ID: %d, 错误: %v", batchID, err)
|
||||
return MapDomainError(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user