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

@@ -2,80 +2,102 @@
namespace App\Services;
use App\Models\Items\Item;
use App\Models\BendingItem;
use Illuminate\Pagination\LengthAwarePaginator;
class BendingItemService extends Service
{
public function list(array $params): LengthAwarePaginator
{
return Item::where('item_category', 'BENDING')
->when($params['item_sep'] ?? null, fn ($q, $v) => $q->where('options->item_sep', $v))
->when($params['item_bending'] ?? null, fn ($q, $v) => $q->where('options->item_bending', $v))
->when($params['material'] ?? null, fn ($q, $v) => $q->where('options->material', 'like', "%{$v}%"))
->when($params['model_UA'] ?? null, fn ($q, $v) => $q->where('options->model_UA', $v))
->when($params['model_name'] ?? null, fn ($q, $v) => $q->where('options->model_name', $v))
return BendingItem::query()
->when($params['item_sep'] ?? null, fn ($q, $v) => $q->where('item_sep', $v))
->when($params['item_bending'] ?? null, fn ($q, $v) => $q->where('item_bending', $v))
->when($params['material'] ?? null, fn ($q, $v) => $q->where('material', 'like', "%{$v}%"))
->when($params['model_UA'] ?? null, fn ($q, $v) => $q->where('model_UA', $v))
->when($params['model_name'] ?? null, fn ($q, $v) => $q->where('model_name', $v))
->when($params['legacy_bending_num'] ?? $params['legacy_bending_id'] ?? null, fn ($q, $v) => $q->where('legacy_bending_id', (int) $v))
->when($params['search'] ?? null, fn ($q, $v) => $q->where(
fn ($q2) => $q2
->where('name', 'like', "%{$v}%")
->where('item_name', 'like', "%{$v}%")
->orWhere('code', 'like', "%{$v}%")
->orWhere('options->search_keyword', 'like', "%{$v}%")
->orWhere('options->item_spec', 'like', "%{$v}%")
->orWhere('item_spec', 'like', "%{$v}%")
->orWhere('legacy_code', 'like', "%{$v}%")
))
->orderBy('code')
->orderByDesc('id')
->paginate($params['size'] ?? 50);
}
public function filters(): array
{
$items = Item::where('item_category', 'BENDING')
->select('options')
->get();
return [
'item_sep' => $items->pluck('options.item_sep')->filter()->unique()->sort()->values(),
'item_bending' => $items->pluck('options.item_bending')->filter()->unique()->sort()->values(),
'material' => $items->pluck('options.material')->filter()->unique()->sort()->values(),
'model_UA' => $items->pluck('options.model_UA')->filter()->unique()->sort()->values(),
'model_name' => $items->pluck('options.model_name')->filter()->unique()->sort()->values(),
'item_sep' => BendingItem::whereNotNull('item_sep')->distinct()->pluck('item_sep')->sort()->values(),
'item_bending' => BendingItem::whereNotNull('item_bending')->distinct()->pluck('item_bending')->sort()->values(),
'material' => BendingItem::whereNotNull('material')->distinct()->pluck('material')->sort()->values(),
'model_UA' => BendingItem::whereNotNull('model_UA')->distinct()->pluck('model_UA')->sort()->values(),
'model_name' => BendingItem::whereNotNull('model_name')->distinct()->pluck('model_name')->sort()->values(),
];
}
public function find(int $id): Item
public function find(int $id): BendingItem
{
return Item::where('item_category', 'BENDING')->findOrFail($id);
return BendingItem::findOrFail($id);
}
public function create(array $data): Item
public function create(array $data): BendingItem
{
$options = $this->buildOptions($data);
return Item::create([
return BendingItem::create([
'tenant_id' => $this->tenantId(),
'item_type' => 'PT',
'item_category' => 'BENDING',
'code' => $data['code'],
'name' => $data['name'],
'unit' => $data['unit'] ?? 'EA',
'options' => $options,
'legacy_code' => $data['legacy_code'] ?? null,
'legacy_bending_id' => $data['legacy_bending_id'] ?? null,
'item_name' => $data['item_name'] ?? $data['name'] ?? '',
'item_sep' => $data['item_sep'] ?? null,
'item_bending' => $data['item_bending'] ?? null,
'material' => $data['material'] ?? null,
'item_spec' => $data['item_spec'] ?? null,
'model_name' => $data['model_name'] ?? null,
'model_UA' => $data['model_UA'] ?? null,
'rail_width' => $data['rail_width'] ?? null,
'exit_direction' => $data['exit_direction'] ?? null,
'box_width' => $data['box_width'] ?? null,
'box_height' => $data['box_height'] ?? null,
'front_bottom' => $data['front_bottom'] ?? $data['front_bottom_width'] ?? null,
'inspection_door' => $data['inspection_door'] ?? null,
'length_code' => $data['length_code'] ?? null,
'length_mm' => $data['length_mm'] ?? null,
'bending_data' => $data['bendingData'] ?? null,
'options' => $this->buildOptions($data),
'is_active' => true,
'created_by' => $this->apiUserId(),
]);
}
public function update(int $id, array $data): Item
public function update(int $id, array $data): BendingItem
{
$item = Item::where('item_category', 'BENDING')->findOrFail($id);
$item = BendingItem::findOrFail($id);
if (isset($data['code'])) {
$item->code = $data['code'];
$columns = [
'code', 'item_name', 'item_sep', 'item_bending',
'material', 'item_spec', 'model_name', 'model_UA',
'rail_width', 'exit_direction', 'box_width', 'box_height',
'front_bottom', 'inspection_door', 'length_code', 'length_mm',
];
foreach ($columns as $col) {
if (array_key_exists($col, $data)) {
$item->{$col} = $data[$col];
}
}
if (isset($data['name'])) {
$item->name = $data['name'];
if (array_key_exists('front_bottom_width', $data) && ! array_key_exists('front_bottom', $data)) {
$item->front_bottom = $data['front_bottom_width'];
}
$optionKeys = self::OPTION_KEYS;
foreach ($optionKeys as $key) {
// 전개도 (JSON 직접 저장)
if (array_key_exists('bendingData', $data)) {
$item->bending_data = $data['bendingData'];
}
// 비정형 속성
foreach (self::OPTION_KEYS as $key) {
if (array_key_exists($key, $data)) {
$item->setOption($key, $data[$key]);
}
@@ -89,14 +111,14 @@ public function update(int $id, array $data): Item
public function delete(int $id): bool
{
$item = Item::where('item_category', 'BENDING')->findOrFail($id);
$item = BendingItem::findOrFail($id);
$item->deleted_by = $this->apiUserId();
$item->save();
return $item->delete();
}
private function buildOptions(array $data): array
private function buildOptions(array $data): ?array
{
$options = [];
foreach (self::OPTION_KEYS as $key) {
@@ -105,15 +127,11 @@ private function buildOptions(array $data): array
}
}
return $options;
return empty($options) ? null : $options;
}
private const OPTION_KEYS = [
'item_name', 'item_sep', 'item_bending', 'item_spec',
'material', 'model_name', 'model_UA', 'search_keyword',
'rail_width', 'registration_date', 'author', 'memo',
'parent_num', 'exit_direction', 'front_bottom_width',
'box_width', 'box_height', 'bendingData',
'prefix', 'length_code', 'length_mm',
'search_keyword', 'registration_date', 'author', 'memo',
'parent_num', 'modified_by',
];
}