Merge branch 'dev' of http://39.117.244.52:3000/kjs/ERP-node into node-nonquery
This commit is contained in:
@@ -203,14 +203,18 @@ export class TableManagementService {
|
||||
|
||||
// 각 컬럼 설정을 순차적으로 업데이트
|
||||
for (const columnSetting of columnSettings) {
|
||||
const columnName =
|
||||
columnSetting.columnLabel || columnSetting.columnName;
|
||||
// columnName은 실제 DB 컬럼명을 유지해야 함
|
||||
const columnName = columnSetting.columnName;
|
||||
if (columnName) {
|
||||
await this.updateColumnSettings(
|
||||
tableName,
|
||||
columnName,
|
||||
columnSetting
|
||||
);
|
||||
} else {
|
||||
logger.warn(
|
||||
`컬럼명이 누락된 설정: ${JSON.stringify(columnSetting)}`
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -339,4 +343,166 @@ export class TableManagementService {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 컬럼 웹 타입 설정
|
||||
*/
|
||||
async updateColumnWebType(
|
||||
tableName: string,
|
||||
columnName: string,
|
||||
webType: string,
|
||||
detailSettings?: Record<string, any>
|
||||
): Promise<void> {
|
||||
try {
|
||||
logger.info(
|
||||
`컬럼 웹 타입 설정 시작: ${tableName}.${columnName} = ${webType}`
|
||||
);
|
||||
|
||||
// 웹 타입별 기본 상세 설정 생성
|
||||
const defaultDetailSettings = this.generateDefaultDetailSettings(webType);
|
||||
|
||||
// 사용자 정의 설정과 기본 설정 병합
|
||||
const finalDetailSettings = {
|
||||
...defaultDetailSettings,
|
||||
...detailSettings,
|
||||
};
|
||||
|
||||
// column_labels 테이블에 해당 컬럼이 있는지 확인
|
||||
const checkQuery = `
|
||||
SELECT COUNT(*) as count
|
||||
FROM column_labels
|
||||
WHERE table_name = $1 AND column_name = $2
|
||||
`;
|
||||
|
||||
const checkResult = await this.client.query(checkQuery, [
|
||||
tableName,
|
||||
columnName,
|
||||
]);
|
||||
|
||||
if (checkResult.rows[0].count > 0) {
|
||||
// 기존 컬럼 라벨 업데이트
|
||||
const updateQuery = `
|
||||
UPDATE column_labels
|
||||
SET web_type = $3, detail_settings = $4, updated_date = NOW()
|
||||
WHERE table_name = $1 AND column_name = $2
|
||||
`;
|
||||
|
||||
await this.client.query(updateQuery, [
|
||||
tableName,
|
||||
columnName,
|
||||
webType,
|
||||
JSON.stringify(finalDetailSettings),
|
||||
]);
|
||||
logger.info(
|
||||
`컬럼 웹 타입 업데이트 완료: ${tableName}.${columnName} = ${webType}`
|
||||
);
|
||||
} else {
|
||||
// 새로운 컬럼 라벨 생성
|
||||
const insertQuery = `
|
||||
INSERT INTO column_labels (
|
||||
table_name, column_name, web_type, detail_settings, created_date, updated_date
|
||||
) VALUES ($1, $2, $3, $4, NOW(), NOW())
|
||||
`;
|
||||
|
||||
await this.client.query(insertQuery, [
|
||||
tableName,
|
||||
columnName,
|
||||
webType,
|
||||
JSON.stringify(finalDetailSettings),
|
||||
]);
|
||||
logger.info(
|
||||
`컬럼 라벨 생성 및 웹 타입 설정 완료: ${tableName}.${columnName} = ${webType}`
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.error(
|
||||
`컬럼 웹 타입 설정 중 오류 발생: ${tableName}.${columnName}`,
|
||||
error
|
||||
);
|
||||
throw new Error(
|
||||
`컬럼 웹 타입 설정 실패: ${error instanceof Error ? error.message : "Unknown error"}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 웹 타입별 기본 상세 설정 생성
|
||||
*/
|
||||
private generateDefaultDetailSettings(webType: string): Record<string, any> {
|
||||
switch (webType) {
|
||||
case "text":
|
||||
return {
|
||||
maxLength: 255,
|
||||
pattern: null,
|
||||
placeholder: null,
|
||||
};
|
||||
|
||||
case "number":
|
||||
return {
|
||||
min: null,
|
||||
max: null,
|
||||
step: 1,
|
||||
precision: 2,
|
||||
};
|
||||
|
||||
case "date":
|
||||
return {
|
||||
format: "YYYY-MM-DD",
|
||||
minDate: null,
|
||||
maxDate: null,
|
||||
};
|
||||
|
||||
case "code":
|
||||
return {
|
||||
codeCategory: null,
|
||||
displayFormat: "label",
|
||||
searchable: true,
|
||||
multiple: false,
|
||||
};
|
||||
|
||||
case "entity":
|
||||
return {
|
||||
referenceTable: null,
|
||||
referenceColumn: null,
|
||||
searchable: true,
|
||||
multiple: false,
|
||||
};
|
||||
|
||||
case "textarea":
|
||||
return {
|
||||
rows: 3,
|
||||
maxLength: 1000,
|
||||
placeholder: null,
|
||||
};
|
||||
|
||||
case "select":
|
||||
return {
|
||||
options: [],
|
||||
multiple: false,
|
||||
searchable: false,
|
||||
};
|
||||
|
||||
case "checkbox":
|
||||
return {
|
||||
defaultChecked: false,
|
||||
label: null,
|
||||
};
|
||||
|
||||
case "radio":
|
||||
return {
|
||||
options: [],
|
||||
inline: false,
|
||||
};
|
||||
|
||||
case "file":
|
||||
return {
|
||||
accept: "*/*",
|
||||
maxSize: 10485760, // 10MB
|
||||
multiple: false,
|
||||
};
|
||||
|
||||
default:
|
||||
return {};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user