From 88d6547e690bed5073f840533df66fa2ad5eca01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B0=95=EC=98=81=EB=B3=B4?= Date: Sat, 21 Mar 2026 15:11:51 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20[=EC=A0=88=EA=B3=A1]=20import=20?= =?UTF-8?q?=EC=8A=A4=ED=81=AC=EB=A6=BD=ED=8A=B8=20+=20GuiderailModel=20cod?= =?UTF-8?q?e/lot=5Fno=20=EB=B6=84=EB=A6=AC=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - BendingCleanReimport: code→앞2자리, lot_no→전체코드, 중복체크 lot_no 기준 - BendingImportMissing: 동일 적용 - BendingModelImport: code→접두사(GR/SB/BB), lot_no→전체코드 - MigrateBendingItemsToNewTable: 동일 적용 - GuiderailModelResource: lot_no 필드 추가 - BendingModel: fillable에 lot_no 추가 --- app/Console/Commands/BendingCleanReimport.php | 5 +++-- app/Console/Commands/BendingImportMissing.php | 5 +++-- app/Console/Commands/BendingModelImport.php | 3 ++- app/Console/Commands/MigrateBendingItemsToNewTable.php | 3 ++- app/Http/Resources/Api/V1/GuiderailModelResource.php | 1 + app/Models/BendingModel.php | 2 +- 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/Console/Commands/BendingCleanReimport.php b/app/Console/Commands/BendingCleanReimport.php index 875d6b01..8297dbc5 100644 --- a/app/Console/Commands/BendingCleanReimport.php +++ b/app/Console/Commands/BendingCleanReimport.php @@ -105,7 +105,8 @@ private function importItem(object $row): BendingItem $bi = BendingItem::create([ 'tenant_id' => $this->tenantId, - 'code' => $code, + 'code' => mb_substr($code, 0, 2), + 'lot_no' => $code, 'legacy_code' => "CHANDJ-{$row->num}", 'legacy_bending_id' => $row->num, 'item_name' => $row->itemName ?: "부품#{$row->num}", @@ -275,7 +276,7 @@ private function generateCode(object $row): string // 중복 방지 일련번호 $seq = 1; while (BendingItem::where('tenant_id', $this->tenantId) - ->where('code', $seq === 1 ? $base : "{$base}-" . str_pad($seq, 2, '0', STR_PAD_LEFT)) + ->where('lot_no', $seq === 1 ? $base : "{$base}-" . str_pad($seq, 2, '0', STR_PAD_LEFT)) ->exists()) { $seq++; } diff --git a/app/Console/Commands/BendingImportMissing.php b/app/Console/Commands/BendingImportMissing.php index 22b9cffc..593f27c2 100644 --- a/app/Console/Commands/BendingImportMissing.php +++ b/app/Console/Commands/BendingImportMissing.php @@ -77,7 +77,8 @@ private function importItem(object $row): BendingItem $bi = BendingItem::create([ 'tenant_id' => $this->tenantId, - 'code' => $code, + 'code' => mb_substr($code, 0, 2), + 'lot_no' => $code, 'legacy_code' => "CHANDJ-{$row->num}", 'legacy_bending_id' => $row->num, 'item_name' => $row->itemName ?: "부품#{$row->num}", @@ -177,7 +178,7 @@ private function generateCode(object $row): string // 중복 방지 일련번호 $seq = 1; while (BendingItem::where('tenant_id', $this->tenantId) - ->where('code', $seq === 1 ? $base : "{$base}-" . str_pad($seq, 2, '0', STR_PAD_LEFT)) + ->where('lot_no', $seq === 1 ? $base : "{$base}-" . str_pad($seq, 2, '0', STR_PAD_LEFT)) ->whereNull('length_code') ->exists()) { $seq++; diff --git a/app/Console/Commands/BendingModelImport.php b/app/Console/Commands/BendingModelImport.php index ce22c57e..e5cd70f1 100644 --- a/app/Console/Commands/BendingModelImport.php +++ b/app/Console/Commands/BendingModelImport.php @@ -120,7 +120,8 @@ private function importModel(object $row, string $type, string $code, array $dat $bm = BendingModel::create(array_merge($data, [ 'tenant_id' => $this->tenantId, 'model_type' => $type, - 'code' => $code, + 'code' => explode('-', $code)[0], + 'lot_no' => $code, 'legacy_num' => $row->num, 'components' => $components, 'material_summary' => $materialSummary, diff --git a/app/Console/Commands/MigrateBendingItemsToNewTable.php b/app/Console/Commands/MigrateBendingItemsToNewTable.php index 029b987e..dedfed1c 100644 --- a/app/Console/Commands/MigrateBendingItemsToNewTable.php +++ b/app/Console/Commands/MigrateBendingItemsToNewTable.php @@ -90,7 +90,8 @@ private function migrateItem(Item $item, int $tenantId): BendingItem $bi = BendingItem::create([ 'tenant_id' => $tenantId, - 'code' => $item->code, + 'code' => mb_substr($item->code, 0, 2), + 'lot_no' => $item->code, 'legacy_code' => $item->code, 'legacy_bending_id' => $opts['legacy_bending_num'] ?? null, // 정규 컬럼 (options에서 승격) diff --git a/app/Http/Resources/Api/V1/GuiderailModelResource.php b/app/Http/Resources/Api/V1/GuiderailModelResource.php index ba94ab04..f77f4c34 100644 --- a/app/Http/Resources/Api/V1/GuiderailModelResource.php +++ b/app/Http/Resources/Api/V1/GuiderailModelResource.php @@ -19,6 +19,7 @@ public function toArray(Request $request): array return [ 'id' => $this->id, 'code' => $this->code, + 'lot_no' => $this->lot_no, 'name' => $this->name, 'is_active' => $this->is_active, // MNG2 호환 diff --git a/app/Models/BendingModel.php b/app/Models/BendingModel.php index cd72abe8..742af838 100644 --- a/app/Models/BendingModel.php +++ b/app/Models/BendingModel.php @@ -16,7 +16,7 @@ class BendingModel extends Model protected $table = 'bending_models'; protected $fillable = [ - 'tenant_id', 'model_type', 'code', 'name', 'legacy_code', 'legacy_num', + 'tenant_id', 'model_type', 'code', 'lot_no', 'name', 'legacy_code', 'legacy_num', 'model_name', 'model_UA', 'item_sep', 'finishing_type', 'author', 'remark', 'check_type', 'rail_width', 'rail_length', 'exit_direction', 'front_bottom_width', 'box_width', 'box_height',