feat(item-master): 잠금 기능 추가 및 FK 레거시 코드 정리
## 잠금 기능 (Lock Feature) - entity_relationships 테이블에 is_locked, locked_by, locked_at 컬럼 추가 - EntityRelationship 모델에 잠금 관련 헬퍼 메서드 추가 - LockCheckTrait 생성 (destroy 시 잠금 체크 공통 로직) - 각 Service의 destroy() 메서드에 잠금 체크 적용 - API 응답에 is_locked 필드 포함 - 한국어 에러 메시지 추가 ## FK 레거시 코드 정리 - ItemMasterSeeder: entity_relationships 기반으로 전환 - ItemPage 모델: FK 기반 sections() 관계 제거 - ItemSectionService: clone() 메서드 FK 제거 - SectionTemplateService: page_id 컬럼 참조 제거 - EntityRelationship::link() 파라미터 순서 통일 ## 기타 - Swagger 스키마에 is_locked 속성 추가 - 프론트엔드 가이드 문서 추가
This commit is contained in:
@@ -4,8 +4,8 @@
|
||||
|
||||
use App\Models\ItemMaster\CustomTab;
|
||||
use App\Models\ItemMaster\EntityRelationship;
|
||||
use App\Models\ItemMaster\ItemBomItem;
|
||||
use App\Models\ItemMaster\ItemField;
|
||||
use App\Models\ItemMaster\ItemMasterField;
|
||||
use App\Models\ItemMaster\ItemPage;
|
||||
use App\Models\ItemMaster\ItemSection;
|
||||
use App\Models\ItemMaster\UnitOption;
|
||||
@@ -18,7 +18,6 @@ class ItemMasterService extends Service
|
||||
*
|
||||
* - pages (linkedSections 기반 중첩)
|
||||
* - sections (모든 독립 섹션)
|
||||
* - masterFields
|
||||
* - customTabs (columnSetting 포함)
|
||||
* - unitOptions
|
||||
*/
|
||||
@@ -57,22 +56,18 @@ public function init(): array
|
||||
->orderBy('created_at', 'desc')
|
||||
->get();
|
||||
|
||||
// 4. 마스터 필드
|
||||
$masterFields = ItemMasterField::where('tenant_id', $tenantId)->get();
|
||||
|
||||
// 5. 커스텀 탭 (컬럼 설정 포함)
|
||||
// 4. 커스텀 탭 (컬럼 설정 포함)
|
||||
$customTabs = CustomTab::with('columnSetting')
|
||||
->where('tenant_id', $tenantId)
|
||||
->orderBy('order_no')
|
||||
->get();
|
||||
|
||||
// 6. 단위 옵션
|
||||
// 5. 단위 옵션
|
||||
$unitOptions = UnitOption::where('tenant_id', $tenantId)->get();
|
||||
|
||||
return [
|
||||
'pages' => $pagesWithSections,
|
||||
'sections' => $sections,
|
||||
'masterFields' => $masterFields,
|
||||
'customTabs' => $customTabs,
|
||||
'unitOptions' => $unitOptions,
|
||||
];
|
||||
@@ -99,15 +94,24 @@ private function getLinkedSections(int $tenantId, int $pageId): array
|
||||
if ($section) {
|
||||
// 섹션에 연결된 필드 (entity_relationships 기반)
|
||||
$linkedFields = $this->getLinkedFields($tenantId, $section->id);
|
||||
// 섹션에 연결된 BOM 항목 (entity_relationships 기반)
|
||||
$linkedBomItems = $this->getLinkedBomItems($tenantId, $section->id);
|
||||
|
||||
$sectionData = $section->toArray();
|
||||
$sectionData['order_no'] = $rel->order_no;
|
||||
// 연결 잠금 상태 (이 페이지-섹션 관계의 잠금)
|
||||
$sectionData['is_locked'] = (bool) $rel->is_locked;
|
||||
|
||||
// FK 기반 필드 + 링크 기반 필드 병합
|
||||
if (! empty($linkedFields)) {
|
||||
$sectionData['fields'] = $linkedFields;
|
||||
}
|
||||
|
||||
// FK 기반 BOM + 링크 기반 BOM 병합
|
||||
if (! empty($linkedBomItems)) {
|
||||
$sectionData['bom_items'] = $linkedBomItems;
|
||||
}
|
||||
|
||||
$sections[] = $sectionData;
|
||||
}
|
||||
}
|
||||
@@ -133,10 +137,39 @@ private function getLinkedFields(int $tenantId, int $sectionId): array
|
||||
if ($field) {
|
||||
$fieldData = $field->toArray();
|
||||
$fieldData['order_no'] = $rel->order_no;
|
||||
// 연결 잠금 상태 (이 섹션-필드 관계의 잠금)
|
||||
$fieldData['is_locked'] = (bool) $rel->is_locked;
|
||||
$fields[] = $fieldData;
|
||||
}
|
||||
}
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
||||
/**
|
||||
* 섹션에 연결된 BOM 항목 조회 (entity_relationships 기반)
|
||||
*/
|
||||
private function getLinkedBomItems(int $tenantId, int $sectionId): array
|
||||
{
|
||||
$relationships = EntityRelationship::where('tenant_id', $tenantId)
|
||||
->where('parent_type', EntityRelationship::TYPE_SECTION)
|
||||
->where('parent_id', $sectionId)
|
||||
->where('child_type', EntityRelationship::TYPE_BOM)
|
||||
->orderBy('order_no')
|
||||
->get();
|
||||
|
||||
$bomItems = [];
|
||||
foreach ($relationships as $rel) {
|
||||
$bomItem = ItemBomItem::find($rel->child_id);
|
||||
if ($bomItem) {
|
||||
$bomData = $bomItem->toArray();
|
||||
$bomData['order_no'] = $rel->order_no;
|
||||
// 연결 잠금 상태 (이 섹션-BOM 관계의 잠금)
|
||||
$bomData['is_locked'] = (bool) $rel->is_locked;
|
||||
$bomItems[] = $bomData;
|
||||
}
|
||||
}
|
||||
|
||||
return $bomItems;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user