feat: [bending] 절곡품 관리 API 완성 + 데이터 마이그레이션
- GuiderailModelController/Service/Resource: 가이드레일/케이스/하단마감재 통합 CRUD - item_category 필터 (GUIDERAIL_MODEL/SHUTTERBOX_MODEL/BOTTOMBAR_MODEL) - BendingItemResource: legacy_bending_num 노출 추가 - ApiKeyMiddleware: guiderail-models, files 화이트리스트 추가 - Swagger: BendingItemApi, GuiderailModelApi 문서 (케이스/하단마감재 필드 포함) - 마이그레이션 커맨드 5개: GuiderailImportLegacy, BendingProductImportLegacy, BendingImportImages, BendingModelImportImages, BendingModelImportAssemblyImages - 데이터: GR 20건 + SB 30건 + BB 10건 + 이미지 473건 R2 업로드
This commit is contained in:
71
app/Http/Resources/Api/V1/GuiderailModelResource.php
Normal file
71
app/Http/Resources/Api/V1/GuiderailModelResource.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources\Api\V1;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class GuiderailModelResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$components = $this->getOption('components', []);
|
||||
$materialSummary = $this->getOption('material_summary');
|
||||
|
||||
// material_summary가 없으면 components에서 계산
|
||||
if (empty($materialSummary) && ! empty($components)) {
|
||||
$materialSummary = $this->calcMaterialSummary($components);
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'code' => $this->code,
|
||||
'name' => $this->name,
|
||||
'item_type' => $this->item_type,
|
||||
'item_category' => $this->item_category,
|
||||
'is_active' => $this->is_active,
|
||||
// 모델 속성
|
||||
'model_name' => $this->getOption('model_name'),
|
||||
'check_type' => $this->getOption('check_type'),
|
||||
'rail_width' => $this->getOption('rail_width'),
|
||||
'rail_length' => $this->getOption('rail_length'),
|
||||
'finishing_type' => $this->getOption('finishing_type'),
|
||||
'item_sep' => $this->getOption('item_sep'),
|
||||
'model_UA' => $this->getOption('model_UA'),
|
||||
'search_keyword' => $this->getOption('search_keyword'),
|
||||
'author' => $this->getOption('author'),
|
||||
'memo' => $this->getOption('memo'),
|
||||
'registration_date' => $this->getOption('registration_date'),
|
||||
// 케이스(SHUTTERBOX_MODEL) 전용
|
||||
'exit_direction' => $this->getOption('exit_direction'),
|
||||
'front_bottom_width' => $this->getOption('front_bottom_width'),
|
||||
'box_width' => $this->getOption('box_width'),
|
||||
'box_height' => $this->getOption('box_height'),
|
||||
// 하단마감재(BOTTOMBAR_MODEL) 전용
|
||||
'bar_width' => $this->getOption('bar_width'),
|
||||
'bar_height' => $this->getOption('bar_height'),
|
||||
// 부품 조합
|
||||
'components' => $components,
|
||||
'material_summary' => $materialSummary,
|
||||
'component_count' => count($components),
|
||||
// 메타
|
||||
'created_at' => $this->created_at?->format('Y-m-d H:i:s'),
|
||||
'updated_at' => $this->updated_at?->format('Y-m-d H:i:s'),
|
||||
];
|
||||
}
|
||||
|
||||
private function calcMaterialSummary(array $components): array
|
||||
{
|
||||
$summary = [];
|
||||
foreach ($components as $comp) {
|
||||
$material = $comp['material'] ?? null;
|
||||
$widthSum = $comp['width_sum'] ?? 0;
|
||||
$qty = $comp['quantity'] ?? 1;
|
||||
if ($material && $widthSum) {
|
||||
$summary[$material] = ($summary[$material] ?? 0) + ($widthSum * $qty);
|
||||
}
|
||||
}
|
||||
|
||||
return $summary;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user