refactor: [절곡] import 스크립트 + GuiderailModel code/lot_no 분리 적용

- BendingCleanReimport: code→앞2자리, lot_no→전체코드, 중복체크 lot_no 기준
- BendingImportMissing: 동일 적용
- BendingModelImport: code→접두사(GR/SB/BB), lot_no→전체코드
- MigrateBendingItemsToNewTable: 동일 적용
- GuiderailModelResource: lot_no 필드 추가
- BendingModel: fillable에 lot_no 추가
This commit is contained in:
2026-03-21 15:11:51 +09:00
parent d6591acdff
commit 88d6547e69
6 changed files with 12 additions and 7 deletions

View File

@@ -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++;
}

View File

@@ -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++;

View File

@@ -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,

View File

@@ -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에서 승격)