mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 13:31:56 +00:00
feat(BE-278): adjustment_recording dto
This commit is contained in:
@@ -39,4 +39,5 @@ type Recording struct {
|
||||
StandardFeedIntake *float64 `gorm:"-"`
|
||||
StandardEggMesh *float64 `gorm:"-"`
|
||||
StandardEggWeight *float64 `gorm:"-"`
|
||||
StandardFcr *float64 `gorm:"-"`
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ type RecordingRelationDTO struct {
|
||||
StandardFeedIntake *float64 `json:"feed_intake_std,omitempty"`
|
||||
StandardEggMesh *float64 `json:"egg_mesh_std,omitempty"`
|
||||
StandardEggWeight *float64 `json:"egg_weight_std,omitempty"`
|
||||
StandardFcr *float64 `json:"fcr_std,omitempty"`
|
||||
Approval approvalDTO.ApprovalRelationDTO `json:"approval"`
|
||||
}
|
||||
|
||||
@@ -165,6 +166,7 @@ func ToRecordingRelationDTO(e entity.Recording) RecordingRelationDTO {
|
||||
StandardFeedIntake: e.StandardFeedIntake,
|
||||
StandardEggMesh: e.StandardEggMesh,
|
||||
StandardEggWeight: e.StandardEggWeight,
|
||||
StandardFcr: e.StandardFcr,
|
||||
Approval: latestApproval,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@ type RecordingRepository interface {
|
||||
GetFeedUsageInGrams(tx *gorm.DB, recordingID uint) (float64, error)
|
||||
GetEggSummaryByRecording(tx *gorm.DB, recordingID uint) (totalQty float64, totalWeightGrams float64, err error)
|
||||
GetCumulativeEggQtyByProjectFlockKandang(tx *gorm.DB, projectFlockKandangId uint, recordTime time.Time) (float64, error)
|
||||
GetFcrStandardNumber(tx *gorm.DB, fcrId uint, currentWeightKg float64) (float64, bool, error)
|
||||
GetProductionWeightAndQtyByProjectFlockID(ctx context.Context, projectFlockID uint) (totalWeight float64, totalQty float64, err error)
|
||||
GetTotalDepletionByProjectFlockID(ctx context.Context, projectFlockID uint) (totalDepletion float64, err error)
|
||||
GetLatestAvgWeightByProjectFlockID(ctx context.Context, projectFlockID uint) (avgWeight float64, err error)
|
||||
@@ -344,12 +345,38 @@ func (r *RecordingRepositoryImpl) GetCumulativeEggQtyByProjectFlockKandang(
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (r *RecordingRepositoryImpl) GetFcrStandardNumber(tx *gorm.DB, fcrId uint, currentWeightKg float64) (float64, bool, error) {
|
||||
if fcrId == 0 || currentWeightKg <= 0 {
|
||||
return 0, false, nil
|
||||
}
|
||||
|
||||
var standard entity.FcrStandard
|
||||
err := tx.
|
||||
Where("fcr_id = ? AND weight >= ?", fcrId, currentWeightKg).
|
||||
Order("weight ASC").
|
||||
First(&standard).Error
|
||||
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
err = tx.
|
||||
Where("fcr_id = ?", fcrId).
|
||||
Order("weight DESC").
|
||||
First(&standard).Error
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return 0, false, nil
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return 0, false, err
|
||||
}
|
||||
|
||||
return standard.FcrNumber, true, nil
|
||||
}
|
||||
|
||||
func (r *RecordingRepositoryImpl) GetProductionWeightAndQtyByProjectFlockID(ctx context.Context, projectFlockID uint) (totalWeight float64, totalQty float64, err error) {
|
||||
// Body-weight tracking is removed; keep stub for report compatibility.
|
||||
return 0, 0, nil
|
||||
}
|
||||
|
||||
|
||||
func (r *RecordingRepositoryImpl) GetTotalDepletionByProjectFlockID(ctx context.Context, projectFlockID uint) (float64, error) {
|
||||
var result float64
|
||||
err := r.DB().WithContext(ctx).
|
||||
|
||||
@@ -1063,6 +1063,7 @@ func (s *recordingService) attachProductionStandard(ctx context.Context, item *e
|
||||
growthDetailRepo := rProductionStandard.NewStandardGrowthDetailRepository(db)
|
||||
|
||||
var standard productionStandardValues
|
||||
var standardFcr *float64
|
||||
if category == string(utils.ProjectFlockCategoryLaying) {
|
||||
detail, err := standardDetailRepo.GetByStandardIDAndWeek(ctx, standardID, week)
|
||||
if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
@@ -1082,6 +1083,21 @@ func (s *recordingService) attachProductionStandard(ctx context.Context, item *e
|
||||
}
|
||||
if growthDetail != nil {
|
||||
standard.FeedIntake = growthDetail.FeedIntake
|
||||
if category == string(utils.ProjectFlockCategoryLaying) && growthDetail.TargetMeanBw != nil && item.ProjectFlockKandang.ProjectFlock.FcrId > 0 {
|
||||
targetWeight := *growthDetail.TargetMeanBw
|
||||
if targetWeight > 10 {
|
||||
targetWeight = targetWeight / 1000
|
||||
}
|
||||
if targetWeight > 0 {
|
||||
fcrStd, ok, err := s.Repository.GetFcrStandardNumber(db, item.ProjectFlockKandang.ProjectFlock.FcrId, targetWeight)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ok {
|
||||
standardFcr = &fcrStd
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
item.StandardHandDay = standard.HandDay
|
||||
@@ -1089,6 +1105,7 @@ func (s *recordingService) attachProductionStandard(ctx context.Context, item *e
|
||||
item.StandardFeedIntake = standard.FeedIntake
|
||||
item.StandardEggMesh = standard.EggMesh
|
||||
item.StandardEggWeight = standard.EggWeight
|
||||
item.StandardFcr = standardFcr
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user