fix: 섹션 복제 시 필드/BOM 링크만 생성하도록 수정
- 섹션 복제 시 필드를 새로 CREATE하던 로직 제거 - 섹션 복제 시 BOM을 새로 CREATE하던 로직 제거 - 기존 필드/BOM ID로 EntityRelationship 링크만 생성 - 독립 엔티티 아키텍처 원칙 준수 (복제 = 자신만 복제 + 관계 링크만 복제) - 불필요한 use 문 제거 (ItemField, ItemBomItem)
This commit is contained in:
@@ -3,8 +3,6 @@
|
||||
namespace App\Services\ItemMaster;
|
||||
|
||||
use App\Models\ItemMaster\EntityRelationship;
|
||||
use App\Models\ItemMaster\ItemBomItem;
|
||||
use App\Models\ItemMaster\ItemField;
|
||||
use App\Models\ItemMaster\ItemSection;
|
||||
use App\Services\Service;
|
||||
use App\Traits\LockCheckTrait;
|
||||
@@ -94,60 +92,28 @@ public function clone(int $id): ItemSection
|
||||
'created_by' => $userId,
|
||||
]);
|
||||
|
||||
// 필드 복제 (entity_relationships 기반)
|
||||
// 기존 필드에 대한 링크만 생성 (필드는 복제하지 않음 - 링크 관계)
|
||||
foreach ($original->getRelation('fields') as $orderNo => $field) {
|
||||
$clonedField = ItemField::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'group_id' => $field->group_id,
|
||||
'field_name' => $field->field_name,
|
||||
'field_type' => $field->field_type,
|
||||
'order_no' => $field->order_no,
|
||||
'is_required' => $field->is_required,
|
||||
'default_value' => $field->default_value,
|
||||
'placeholder' => $field->placeholder,
|
||||
'display_condition' => $field->display_condition,
|
||||
'validation_rules' => $field->validation_rules,
|
||||
'options' => $field->options,
|
||||
'properties' => $field->properties,
|
||||
'created_by' => $userId,
|
||||
]);
|
||||
|
||||
// 섹션-필드 관계 생성
|
||||
EntityRelationship::link(
|
||||
$tenantId,
|
||||
EntityRelationship::TYPE_SECTION,
|
||||
$cloned->id,
|
||||
EntityRelationship::TYPE_FIELD,
|
||||
$clonedField->id,
|
||||
$field->id,
|
||||
$field->order_no,
|
||||
null,
|
||||
$field->group_id
|
||||
);
|
||||
}
|
||||
|
||||
// BOM 항목 복제 (entity_relationships 기반)
|
||||
// 기존 BOM에 대한 링크만 생성 (BOM은 복제하지 않음 - 링크 관계)
|
||||
foreach ($original->getRelation('bomItems') as $orderNo => $bom) {
|
||||
$clonedBom = ItemBomItem::create([
|
||||
'tenant_id' => $tenantId,
|
||||
'group_id' => $bom->group_id,
|
||||
'item_code' => $bom->item_code,
|
||||
'item_name' => $bom->item_name,
|
||||
'quantity' => $bom->quantity,
|
||||
'unit' => $bom->unit,
|
||||
'unit_price' => $bom->unit_price,
|
||||
'total_price' => $bom->total_price,
|
||||
'spec' => $bom->spec,
|
||||
'note' => $bom->note,
|
||||
'created_by' => $userId,
|
||||
]);
|
||||
|
||||
// 섹션-BOM 관계 생성
|
||||
EntityRelationship::link(
|
||||
$tenantId,
|
||||
EntityRelationship::TYPE_SECTION,
|
||||
$cloned->id,
|
||||
EntityRelationship::TYPE_BOM,
|
||||
$clonedBom->id,
|
||||
$bom->id,
|
||||
$orderNo,
|
||||
null,
|
||||
$bom->group_id
|
||||
|
||||
Reference in New Issue
Block a user