배치 대략적인 완료

This commit is contained in:
dohyeons
2025-11-21 02:25:25 +09:00
parent eb6fe57839
commit 0450390b2a
11 changed files with 2064 additions and 357 deletions

View File

@@ -138,6 +138,7 @@ export const createLayout = async (
warehouseKey,
layoutName,
description,
hierarchyConfig,
objects,
} = req.body;
@@ -147,9 +148,9 @@ export const createLayout = async (
const layoutQuery = `
INSERT INTO digital_twin_layout (
company_code, external_db_connection_id, warehouse_key,
layout_name, description, created_by, updated_by
layout_name, description, hierarchy_config, created_by, updated_by
)
VALUES ($1, $2, $3, $4, $5, $6, $6)
VALUES ($1, $2, $3, $4, $5, $6, $7, $7)
RETURNING *
`;
@@ -159,6 +160,7 @@ export const createLayout = async (
warehouseKey,
layoutName,
description,
hierarchyConfig ? JSON.stringify(hierarchyConfig) : null,
userId,
]);
@@ -174,9 +176,10 @@ export const createLayout = async (
rotation, color,
area_key, loca_key, loc_type,
material_count, material_preview_height,
parent_id, display_order, locked
parent_id, display_order, locked,
hierarchy_level, parent_key, external_key
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22)
`;
for (const obj of objects) {
@@ -200,6 +203,9 @@ export const createLayout = async (
obj.parentId || null,
obj.displayOrder || 0,
obj.locked || false,
obj.hierarchyLevel || 1,
obj.parentKey || null,
obj.externalKey || null,
]);
}
}
@@ -240,7 +246,14 @@ export const updateLayout = async (
const companyCode = req.user?.companyCode;
const userId = req.user?.userId;
const { id } = req.params;
const { layoutName, description, objects } = req.body;
const {
layoutName,
description,
hierarchyConfig,
externalDbConnectionId,
warehouseKey,
objects,
} = req.body;
await client.query("BEGIN");
@@ -249,15 +262,21 @@ export const updateLayout = async (
UPDATE digital_twin_layout
SET layout_name = $1,
description = $2,
updated_by = $3,
hierarchy_config = $3,
external_db_connection_id = $4,
warehouse_key = $5,
updated_by = $6,
updated_at = NOW()
WHERE id = $4 AND company_code = $5
WHERE id = $7 AND company_code = $8
RETURNING *
`;
const layoutResult = await client.query(updateLayoutQuery, [
layoutName,
description,
hierarchyConfig ? JSON.stringify(hierarchyConfig) : null,
externalDbConnectionId || null,
warehouseKey || null,
userId,
id,
companyCode,
@@ -277,7 +296,7 @@ export const updateLayout = async (
[id]
);
// 새 객체 저장
// 새 객체 저장 (부모-자식 관계 처리)
if (objects && objects.length > 0) {
const objectQuery = `
INSERT INTO digital_twin_objects (
@@ -287,12 +306,53 @@ export const updateLayout = async (
rotation, color,
area_key, loca_key, loc_type,
material_count, material_preview_height,
parent_id, display_order, locked
parent_id, display_order, locked,
hierarchy_level, parent_key, external_key
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22)
RETURNING id
`;
for (const obj of objects) {
// 임시 ID (음수) → 실제 DB ID 매핑
const idMapping: { [tempId: number]: number } = {};
// 1단계: 부모 객체 먼저 저장 (parentId가 없는 것들)
for (const obj of objects.filter((o) => !o.parentId)) {
const result = await client.query(objectQuery, [
id,
obj.type,
obj.name,
obj.position.x,
obj.position.y,
obj.position.z,
obj.size.x,
obj.size.y,
obj.size.z,
obj.rotation || 0,
obj.color,
obj.areaKey || null,
obj.locaKey || null,
obj.locType || null,
obj.materialCount || 0,
obj.materialPreview?.height || null,
null, // parent_id
obj.displayOrder || 0,
obj.locked || false,
obj.hierarchyLevel || 1,
obj.parentKey || null,
obj.externalKey || null,
]);
// 임시 ID와 실제 DB ID 매핑
if (obj.id) {
idMapping[obj.id] = result.rows[0].id;
}
}
// 2단계: 자식 객체 저장 (parentId가 있는 것들)
for (const obj of objects.filter((o) => o.parentId)) {
const realParentId = idMapping[obj.parentId!] || null;
await client.query(objectQuery, [
id,
obj.type,
@@ -310,9 +370,12 @@ export const updateLayout = async (
obj.locType || null,
obj.materialCount || 0,
obj.materialPreview?.height || null,
obj.parentId || null,
realParentId, // 실제 DB ID 사용
obj.displayOrder || 0,
obj.locked || false,
obj.hierarchyLevel || 1,
obj.parentKey || null,
obj.externalKey || null,
]);
}
}