mirror of
https://gitlab.com/mbugroup/lti-api.git
synced 2026-06-09 15:07:49 +00:00
initial refactori trasnfer to laying, and depretitation to 25 week
This commit is contained in:
@@ -244,8 +244,12 @@ func AttachProductionStandards(ctx context.Context, db *gorm.DB, warnOnly bool,
|
||||
growthDetailByStd[standardID] = growthMap
|
||||
}
|
||||
|
||||
// Batch-load laying transfer targets → source PFK chick_in_dates
|
||||
// untuk menentukan actual chicken week (bukan hardcode LayingWeekStart offset)
|
||||
// Batch-load laying transfer targets → EARLIEST source PFK chick_in_date per target.
|
||||
// Multi-source: 1 target kandang bisa menerima dari multiple transfer terpisah. Untuk
|
||||
// production standard week, kita pakai chick_in_date PALING AWAL (umur paling tua) sebagai
|
||||
// anchor — agar perbandingan standar produksi tidak under-estimate umur ayam.
|
||||
// Source diambil dari header `laying_transfers.source_project_flock_kandang_id` (single source
|
||||
// of truth per migration 20260307130342), bukan dari `laying_transfer_sources`.
|
||||
type transferChickIn struct {
|
||||
TargetPFKID uint
|
||||
ChickInDate time.Time
|
||||
@@ -255,14 +259,16 @@ func AttachProductionStandards(ctx context.Context, db *gorm.DB, warnOnly bool,
|
||||
if len(layingPFKIDs) > 0 {
|
||||
var results []transferChickIn
|
||||
db.Raw(`
|
||||
SELECT ltt.target_project_flock_kandang_id AS target_pfk_id, pc.chick_in_date
|
||||
SELECT ltt.target_project_flock_kandang_id AS target_pfk_id,
|
||||
MIN(pc.chick_in_date) AS chick_in_date
|
||||
FROM laying_transfer_targets ltt
|
||||
JOIN laying_transfer_sources lts ON lts.laying_transfer_id = ltt.laying_transfer_id
|
||||
JOIN project_chickins pc ON pc.project_flock_kandang_id = lts.source_project_flock_kandang_id
|
||||
JOIN laying_transfers lt ON lt.id = ltt.laying_transfer_id AND lt.deleted_at IS NULL
|
||||
JOIN project_chickins pc ON pc.project_flock_kandang_id = lt.source_project_flock_kandang_id
|
||||
WHERE ltt.target_project_flock_kandang_id IN ?
|
||||
AND ltt.deleted_at IS NULL
|
||||
AND lts.deleted_at IS NULL
|
||||
AND lt.source_project_flock_kandang_id IS NOT NULL
|
||||
AND pc.deleted_at IS NULL
|
||||
GROUP BY ltt.target_project_flock_kandang_id
|
||||
`, layingPFKIDs).Scan(&results)
|
||||
for _, r := range results {
|
||||
sourceChickInByTarget[r.TargetPFKID] = r.ChickInDate
|
||||
|
||||
Reference in New Issue
Block a user