feat:검사 기준서 동적화 + 외부 키 매핑 동적화

- 템플릿별 동적 필드 정의 (document_template_section_fields)
- 외부 키 매핑 동적화 (document_template_links + link_values)
- 문서 레벨 연결 (document_links)
- 시스템 프리셋 (document_template_field_presets)
- section_items에 field_values JSON 컬럼 추가
- 기존 고정 필드 → 동적 field_values 데이터 마이그레이션
- search_api → source_table 전환 마이그레이션

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-04 08:37:55 +09:00
parent 3d20c6979d
commit af42c115ae
14 changed files with 763 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Models\Documents;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 문서 레벨 연결 (실제 문서 작성 시 연결된 대상 기록)
*/
class DocumentLink extends Model
{
protected $table = 'document_links';
public $timestamps = false;
protected $fillable = [
'document_id',
'link_id',
'linkable_id',
'sort_order',
'created_at',
];
protected $casts = [
'sort_order' => 'integer',
];
public function document(): BelongsTo
{
return $this->belongsTo(Document::class, 'document_id');
}
public function linkDefinition(): BelongsTo
{
return $this->belongsTo(DocumentTemplateLink::class, 'link_id');
}
}

View File

@@ -91,6 +91,24 @@ public function columns(): HasMany
->orderBy('sort_order');
}
/**
* 검사 기준서 동적 필드 정의
*/
public function sectionFields(): HasMany
{
return $this->hasMany(DocumentTemplateSectionField::class, 'template_id')
->orderBy('sort_order');
}
/**
* 외부 키 매핑 정의
*/
public function links(): HasMany
{
return $this->hasMany(DocumentTemplateLink::class, 'template_id')
->orderBy('sort_order');
}
// =========================================================================
// Scopes
// =========================================================================

View File

@@ -0,0 +1,27 @@
<?php
namespace App\Models\Documents;
use Illuminate\Database\Eloquent\Model;
/**
* 시스템 프리셋 (tenant_id 없음)
*/
class DocumentTemplateFieldPreset extends Model
{
protected $table = 'document_template_field_presets';
protected $fillable = [
'name',
'category',
'fields',
'links',
'sort_order',
];
protected $casts = [
'fields' => 'array',
'links' => 'array',
'sort_order' => 'integer',
];
}

View File

@@ -0,0 +1,45 @@
<?php
namespace App\Models\Documents;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
/**
* 템플릿별 외부 키 매핑 정의
*/
class DocumentTemplateLink extends Model
{
protected $table = 'document_template_links';
protected $fillable = [
'template_id',
'link_key',
'label',
'link_type',
'source_table',
'search_params',
'display_fields',
'is_required',
'sort_order',
];
protected $casts = [
'search_params' => 'array',
'display_fields' => 'array',
'is_required' => 'boolean',
'sort_order' => 'integer',
];
public function template(): BelongsTo
{
return $this->belongsTo(DocumentTemplate::class, 'template_id');
}
public function linkValues(): HasMany
{
return $this->hasMany(DocumentTemplateLinkValue::class, 'link_id')
->orderBy('sort_order');
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Models\Documents;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 템플릿 레벨 연결 값 (기존 linked_item_ids/linked_process_id 대체)
*/
class DocumentTemplateLinkValue extends Model
{
protected $table = 'document_template_link_values';
public $timestamps = false;
protected $fillable = [
'template_id',
'link_id',
'linkable_id',
'sort_order',
'created_at',
];
protected $casts = [
'sort_order' => 'integer',
];
public function template(): BelongsTo
{
return $this->belongsTo(DocumentTemplate::class, 'template_id');
}
public function link(): BelongsTo
{
return $this->belongsTo(DocumentTemplateLink::class, 'link_id');
}
}

View File

@@ -0,0 +1,36 @@
<?php
namespace App\Models\Documents;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
/**
* 템플릿별 검사 기준서 동적 필드 정의
*/
class DocumentTemplateSectionField extends Model
{
protected $table = 'document_template_section_fields';
protected $fillable = [
'template_id',
'field_key',
'label',
'field_type',
'options',
'width',
'is_required',
'sort_order',
];
protected $casts = [
'options' => 'array',
'is_required' => 'boolean',
'sort_order' => 'integer',
];
public function template(): BelongsTo
{
return $this->belongsTo(DocumentTemplate::class, 'template_id');
}
}

View File

@@ -28,17 +28,38 @@ class DocumentTemplateSectionItem extends Model
'item',
'standard',
'tolerance',
'standard_criteria',
'method',
'measurement_type',
'frequency_n',
'frequency_c',
'frequency',
'regulation',
'field_values',
'sort_order',
];
protected $casts = [
'tolerance' => 'array',
'standard_criteria' => 'array',
'field_values' => 'array',
'sort_order' => 'integer',
'frequency_n' => 'integer',
'frequency_c' => 'integer',
];
/**
* field_values 우선, 없으면 기존 컬럼 fallback
*/
public function getFieldValue(string $key): mixed
{
if (! empty($this->field_values) && array_key_exists($key, $this->field_values)) {
return $this->field_values[$key];
}
return $this->attributes[$key] ?? null;
}
public function section(): BelongsTo
{
return $this->belongsTo(DocumentTemplateSection::class, 'section_id');