mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-05-20 21:41:55 +00:00
[FIX/BE-US] adjustment recording
This commit is contained in:
@@ -171,6 +171,7 @@ func (r *RecordingRepositoryImpl) GenerateNextDay(tx *gorm.DB, projectFlockKanda
|
||||
var days []int
|
||||
if err := tx.Model(&entity.Recording{}).
|
||||
Where("project_flock_kandangs_id = ?", projectFlockKandangId).
|
||||
Where("deleted_at IS NULL").
|
||||
Where("day IS NOT NULL").
|
||||
Pluck("day", &days).Error; err != nil {
|
||||
return 0, err
|
||||
@@ -399,7 +400,7 @@ func (r *RecordingRepositoryImpl) GetEggSummaryByRecording(tx *gorm.DB, recordin
|
||||
}
|
||||
err = tx.
|
||||
Table("recording_eggs").
|
||||
Select("COALESCE(SUM(recording_eggs.qty), 0) AS total_qty, COALESCE(SUM(recording_eggs.qty * COALESCE(recording_eggs.weight, 0)), 0) AS total_weight_grams").
|
||||
Select("COALESCE(SUM(recording_eggs.qty), 0) AS total_qty, COALESCE(SUM(COALESCE(recording_eggs.weight, 0) * 1000), 0) AS total_weight_grams").
|
||||
Where("recording_eggs.recording_id = ?", recordingID).
|
||||
Scan(&result).Error
|
||||
if err != nil {
|
||||
@@ -485,7 +486,7 @@ func (r *RecordingRepositoryImpl) GetTotalEggProductionWeightByProjectFlockID(ct
|
||||
var result float64
|
||||
err := r.DB().WithContext(ctx).
|
||||
Table("recording_eggs").
|
||||
Select("COALESCE(SUM(recording_eggs.qty * recording_eggs.weight), 0) / 1000").
|
||||
Select("COALESCE(SUM(recording_eggs.weight), 0)").
|
||||
Joins("JOIN recordings ON recordings.id = recording_eggs.recording_id").
|
||||
Joins("JOIN project_flock_kandangs ON project_flock_kandangs.id = recordings.project_flock_kandangs_id").
|
||||
Where("project_flock_kandangs.project_flock_id = ?", projectFlockID).
|
||||
|
||||
@@ -1157,7 +1157,7 @@ func eggsMatch(existing []entity.RecordingEgg, incoming []validation.Egg) bool {
|
||||
}
|
||||
current := existingTotals[egg.ProductWarehouseId]
|
||||
current.Qty += egg.Qty
|
||||
current.Weight += float64(egg.Qty) * weight
|
||||
current.Weight += weight
|
||||
existingTotals[egg.ProductWarehouseId] = current
|
||||
}
|
||||
|
||||
@@ -1169,7 +1169,7 @@ func eggsMatch(existing []entity.RecordingEgg, incoming []validation.Egg) bool {
|
||||
}
|
||||
current := incomingTotals[egg.ProductWarehouseId]
|
||||
current.Qty += egg.Qty
|
||||
current.Weight += float64(egg.Qty) * weight
|
||||
current.Weight += weight
|
||||
incomingTotals[egg.ProductWarehouseId] = current
|
||||
}
|
||||
|
||||
@@ -1328,7 +1328,7 @@ func (s *recordingService) computeAndUpdateMetrics(ctx context.Context, tx *gorm
|
||||
|
||||
var eggMass float64
|
||||
if remainingChick > 0 && totalEggWeightGrams > 0 {
|
||||
eggMass = totalEggWeightGrams / remainingChick
|
||||
eggMass = (totalEggWeightGrams / remainingChick) / 1000
|
||||
updates["egg_mass"] = eggMass
|
||||
recording.EggMass = &eggMass
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user