summaryrefslogtreecommitdiff
path: root/lib/sedp/sync-object-class.ts
diff options
context:
space:
mode:
Diffstat (limited to 'lib/sedp/sync-object-class.ts')
-rw-r--r--lib/sedp/sync-object-class.ts69
1 files changed, 55 insertions, 14 deletions
diff --git a/lib/sedp/sync-object-class.ts b/lib/sedp/sync-object-class.ts
index 1a325407..d48a8e7c 100644
--- a/lib/sedp/sync-object-class.ts
+++ b/lib/sedp/sync-object-class.ts
@@ -115,6 +115,43 @@ export async function getCodeListsByID(projectCode: string): Promise<SubClassCod
}
}
+function collectInheritedAttributes(
+ classId: string,
+ allClasses: ObjectClass[]
+): LinkAttribute[] {
+ const classMap = new Map(allClasses.map(cls => [cls.CLS_ID, cls]));
+ const collectedAttributes: LinkAttribute[] = [];
+ const seenAttributeIds = new Set<string>();
+
+ // 현재 클래스부터 시작해서 부모를 따라 올라가며 속성 수집
+ function collectFromClass(currentClassId: string | null): void {
+ if (!currentClassId) return;
+
+ const currentClass = classMap.get(currentClassId);
+ if (!currentClass) return;
+
+ // 먼저 부모 클래스의 속성을 수집 (상위부터 하위 순서로)
+ if (currentClass.PRT_CLS_ID) {
+ collectFromClass(currentClass.PRT_CLS_ID);
+ }
+
+ // 현재 클래스의 LNK_ATT 추가 (중복 제거)
+ if (currentClass.LNK_ATT && Array.isArray(currentClass.LNK_ATT)) {
+ for (const attr of currentClass.LNK_ATT) {
+ if (!seenAttributeIds.has(attr.ATT_ID)) {
+ seenAttributeIds.add(attr.ATT_ID);
+ collectedAttributes.push(attr);
+ }
+ }
+ }
+ }
+
+ collectFromClass(classId);
+
+ // SEQ 순서로 정렬
+ return collectedAttributes.sort((a, b) => (a.SEQ || 0) - (b.SEQ || 0));
+}
+
// 태그 클래스 속성 저장 함수
async function saveTagClassAttributes(
tagClassId: number,
@@ -579,15 +616,18 @@ async function saveObjectClassesToDatabase(
totalChanged += toInsert.length;
console.log(`프로젝트 ID ${projectId}에 ${toInsert.length}개의 새 오브젝트 클래스 추가 완료`);
- // 새로 삽입된 각 클래스의 LNK_ATT 속성 처리
+ // 새로 삽입된 각 클래스의 상속된 LNK_ATT 속성 처리
for (const insertedClass of insertedClasses) {
- const originalClass = classesToSave.find(cls => cls.CLS_ID === insertedClass.code);
- if (originalClass && originalClass.LNK_ATT && originalClass.LNK_ATT.length > 0) {
- try {
- await saveTagClassAttributes(insertedClass.id, originalClass.LNK_ATT);
- } catch (error) {
- console.error(`태그 클래스 ${insertedClass.code}의 속성 저장 실패:`, error);
+ try {
+ // 🔥 수정된 부분: 상속된 속성 수집
+ const inheritedAttributes = collectInheritedAttributes(insertedClass.code, classes);
+
+ if (inheritedAttributes.length > 0) {
+ await saveTagClassAttributes(insertedClass.id, inheritedAttributes);
+ console.log(`태그 클래스 ${insertedClass.code}에 ${inheritedAttributes.length}개의 상속된 속성 저장 완료`);
}
+ } catch (error) {
+ console.error(`태그 클래스 ${insertedClass.code}의 속성 저장 실패:`, error);
}
}
}
@@ -621,13 +661,14 @@ async function saveObjectClassesToDatabase(
.limit(1);
if (updatedClass.length > 0) {
- const originalClass = classesToSave.find(cls => cls.CLS_ID === item.code);
- if (originalClass && originalClass.LNK_ATT) {
- try {
- await saveTagClassAttributes(updatedClass[0].id, originalClass.LNK_ATT);
- } catch (error) {
- console.error(`태그 클래스 ${item.code}의 속성 업데이트 실패:`, error);
- }
+ try {
+ // 🔥 수정된 부분: 상속된 속성 수집
+ const inheritedAttributes = collectInheritedAttributes(item.code, classes);
+
+ await saveTagClassAttributes(updatedClass[0].id, inheritedAttributes);
+ console.log(`태그 클래스 ${item.code}에 ${inheritedAttributes.length}개의 상속된 속성 업데이트 완료`);
+ } catch (error) {
+ console.error(`태그 클래스 ${item.code}의 속성 업데이트 실패:`, error);
}
}