feat: [bending] 절곡품 전용 테이블 분리 API

- bending_items 전용 테이블 생성 (items.options → 정규 컬럼 승격)
- bending_models 전용 테이블 생성 (가이드레일/케이스/하단마감재 통합)
- bending_data JSON 통합 (별도 테이블 → bending_items.bending_data 컬럼)
- bending_item_mappings 테이블 DROP (bending_items.code에 흡수)
- BendingItemService/BendingCodeService → BendingItem 모델 전환
- GuiderailModelService component 이미지 자동 복사
- ItemsFileController bending_items/bending_models 폴백 지원
- Swagger 스키마 업데이트
This commit is contained in:
강영보
2026-03-19 19:54:23 +09:00
parent 623298dd82
commit c29090a0b8
32 changed files with 3114 additions and 490 deletions

View File

@@ -9,10 +9,9 @@ class GuiderailModelResource extends JsonResource
{
public function toArray(Request $request): array
{
$components = $this->getOption('components', []);
$materialSummary = $this->getOption('material_summary');
$components = $this->components ?? [];
$materialSummary = $this->material_summary;
// material_summary가 없으면 components에서 계산
if (empty($materialSummary) && ! empty($components)) {
$materialSummary = $this->calcMaterialSummary($components);
}
@@ -21,29 +20,34 @@ public function toArray(Request $request): array
'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'),
// MNG2 호환
'item_type' => 'FG',
'item_category' => $this->model_type,
// 모델 속성 (정규 컬럼)
'model_name' => $this->model_name,
'check_type' => $this->check_type,
'rail_width' => $this->rail_width ? (int) $this->rail_width : null,
'rail_length' => $this->rail_length ? (int) $this->rail_length : null,
'finishing_type' => $this->finishing_type,
'item_sep' => $this->item_sep,
'model_UA' => $this->model_UA,
'search_keyword' => $this->search_keyword,
'author' => $this->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'),
'registration_date' => $this->registration_date?->format('Y-m-d'),
// 케이스 전용
'exit_direction' => $this->exit_direction,
'front_bottom_width' => $this->front_bottom_width ? (int) $this->front_bottom_width : null,
'box_width' => $this->box_width ? (int) $this->box_width : null,
'box_height' => $this->box_height ? (int) $this->box_height : null,
// 하단마감재 전용
'bar_width' => $this->bar_width ? (int) $this->bar_width : null,
'bar_height' => $this->bar_height ? (int) $this->bar_height : null,
// 수정자
'modified_by' => $this->getOption('modified_by'),
// 이미지
'image_file_id' => $this->getImageFileId(),
// 부품 조합
'components' => $components,
'material_summary' => $materialSummary,
@@ -54,18 +58,36 @@ public function toArray(Request $request): array
];
}
private function getImageFileId(): ?int
{
$file = \App\Models\Commons\File::where('document_id', $this->id)
->where('document_type', 'bending_model')
->where('field_key', 'assembly_image')
->whereNull('deleted_at')
->orderByDesc('id')
->first();
if (! $file) {
$file = $this->files()
->where('field_key', 'bending_diagram')
->orderByDesc('id')
->first();
}
return $file?->id;
}
private function calcMaterialSummary(array $components): array
{
$summary = [];
foreach ($components as $comp) {
$material = $comp['material'] ?? null;
$widthSum = $comp['width_sum'] ?? 0;
$widthSum = $comp['widthsum'] ?? $comp['width_sum'] ?? 0;
$qty = $comp['quantity'] ?? 1;
if ($material && $widthSum) {
$summary[$material] = ($summary[$material] ?? 0) + ($widthSum * $qty);
}
}
return $summary;
}
}