feat: [bending] 가이드레일/케이스 부품 조합에 기초자료 품목코드(item_code) 매핑 추가

This commit is contained in:
김보곤
2026-03-21 11:42:13 +09:00
parent e4f698654b
commit 917b75d4b4

View File

@@ -50,7 +50,7 @@ public function toArray(Request $request): array
'image_file_id' => $this->getImageFileId(),
'image_url' => $this->getImageUrl(),
// 부품 조합
'components' => $this->enrichComponentsWithImageUrls($components),
'components' => $this->enrichComponents($components),
'material_summary' => $materialSummary,
'component_count' => count($components),
// 메타
@@ -88,23 +88,32 @@ private function getImageUrl(): ?string
return $this->getImageFile()?->presignedUrl();
}
private function enrichComponentsWithImageUrls(array $components): array
private function enrichComponents(array $components): array
{
$fileIds = array_filter(array_column($components, 'image_file_id'));
if (empty($fileIds)) {
return $components;
}
// sam_item_id → 기초자료 품목코드 매핑
$itemIds = array_filter(array_column($components, 'sam_item_id'));
$itemCodes = ! empty($itemIds)
? \App\Models\BendingItem::withoutGlobalScopes()->whereIn('id', $itemIds)->pluck('code', 'id')->toArray()
: [];
$files = \App\Models\Commons\File::whereIn('id', $fileIds)
->whereNull('deleted_at')
->get()
->keyBy('id');
// image_file_id → presigned URL 매핑
$fileIds = array_filter(array_column($components, 'image_file_id'));
$files = ! empty($fileIds)
? \App\Models\Commons\File::whereIn('id', $fileIds)->whereNull('deleted_at')->get()->keyBy('id')
: collect();
foreach ($components as &$comp) {
$samId = $comp['sam_item_id'] ?? null;
$comp['item_code'] = $samId ? ($itemCodes[$samId] ?? null) : null;
$fileId = $comp['image_file_id'] ?? null;
$comp['image_url'] = $fileId && isset($files[$fileId])
? $files[$fileId]->presignedUrl()
: null;
try {
$comp['image_url'] = $fileId && $files->has($fileId)
? $files[$fileId]->presignedUrl()
: null;
} catch (\Throwable) {
$comp['image_url'] = null;
}
}
unset($comp);
@@ -122,6 +131,7 @@ private function calcMaterialSummary(array $components): array
$summary[$material] = ($summary[$material] ?? 0) + ($widthSum * $qty);
}
}
return $summary;
}
}