feat: 품목 마스터 소스 매핑 기능 추가
- ItemField 모델: 소스 매핑 컬럼 추가 (source_table, source_column 등) - ItemPage 모델: source_table 컬럼 추가 - ItemDataService: 동적 데이터 조회 서비스 - ItemMasterApi Swagger 업데이트 - ItemTypeSeeder: 품목 유형 시더 - 스펙 문서: ITEM_MASTER_FIELD_INTEGRATION_PLAN.md
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('item_pages', function (Blueprint $table) {
|
||||
// source_table 컬럼 추가
|
||||
$table->string('source_table', 100)
|
||||
->nullable()
|
||||
->after('item_type')
|
||||
->comment('실제 저장 테이블명 (products, materials 등)');
|
||||
|
||||
// 인덱스
|
||||
$table->index('source_table', 'idx_source_table');
|
||||
});
|
||||
|
||||
// 기존 데이터 업데이트: item_type 기반으로 source_table 설정
|
||||
DB::table('item_pages')
|
||||
->whereIn('item_type', ['FG', 'PT'])
|
||||
->update(['source_table' => 'products']);
|
||||
|
||||
DB::table('item_pages')
|
||||
->whereIn('item_type', ['SM', 'RM', 'CS'])
|
||||
->update(['source_table' => 'materials']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('item_pages', function (Blueprint $table) {
|
||||
$table->dropIndex('idx_source_table');
|
||||
$table->dropColumn('source_table');
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('item_fields', function (Blueprint $table) {
|
||||
// 내부용 매핑 컬럼 (API 응답에서 제외)
|
||||
$table->string('source_table', 100)
|
||||
->nullable()
|
||||
->after('properties')
|
||||
->comment('내부용: 원본 테이블명 (products, materials 등)');
|
||||
|
||||
$table->string('source_column', 100)
|
||||
->nullable()
|
||||
->after('source_table')
|
||||
->comment('내부용: 원본 컬럼명 (code, name 등)');
|
||||
|
||||
$table->enum('storage_type', ['column', 'json'])
|
||||
->default('json')
|
||||
->after('source_column')
|
||||
->comment('내부용: 저장방식 (column=DB컬럼, json=attributes/options)');
|
||||
|
||||
$table->string('json_path', 200)
|
||||
->nullable()
|
||||
->after('storage_type')
|
||||
->comment('내부용: JSON 저장 경로 (예: attributes.custom_size)');
|
||||
|
||||
// 인덱스
|
||||
$table->index(['source_table', 'source_column'], 'idx_source_mapping');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('item_fields', function (Blueprint $table) {
|
||||
$table->dropIndex('idx_source_mapping');
|
||||
$table->dropColumn(['source_table', 'source_column', 'storage_type', 'json_path']);
|
||||
});
|
||||
}
|
||||
};
|
||||
45
database/seeders/ItemTypeSeeder.php
Normal file
45
database/seeders/ItemTypeSeeder.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ItemTypeSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
* common_codes 테이블에 item_type 그룹 데이터 시딩
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$tenantId = 1; // 기본 테넌트
|
||||
|
||||
// code_group = 'item_type' (컬럼명과 동일하게!)
|
||||
$itemTypes = [
|
||||
['code_group' => 'item_type', 'code' => 'FG', 'name' => '완제품', 'tenant_id' => $tenantId],
|
||||
['code_group' => 'item_type', 'code' => 'PT', 'name' => '반제품', 'tenant_id' => $tenantId],
|
||||
['code_group' => 'item_type', 'code' => 'SM', 'name' => '부자재', 'tenant_id' => $tenantId],
|
||||
['code_group' => 'item_type', 'code' => 'RM', 'name' => '원자재', 'tenant_id' => $tenantId],
|
||||
['code_group' => 'item_type', 'code' => 'CS', 'name' => '소모품', 'tenant_id' => $tenantId],
|
||||
];
|
||||
|
||||
foreach ($itemTypes as $index => $item) {
|
||||
DB::table('common_codes')->updateOrInsert(
|
||||
[
|
||||
'code_group' => $item['code_group'],
|
||||
'code' => $item['code'],
|
||||
'tenant_id' => $item['tenant_id'],
|
||||
],
|
||||
array_merge($item, [
|
||||
'sort_order' => $index + 1,
|
||||
'is_active' => true,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
$this->command->info('ItemTypeSeeder: '.count($itemTypes).'개 item_type 코드가 시딩되었습니다.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user