제어관리 회사코드 저장 안되는 문제 수정

This commit is contained in:
kjs
2025-12-11 10:41:28 +09:00
parent 088596480f
commit f272f0c4c7
6 changed files with 962 additions and 751 deletions

View File

@@ -117,6 +117,18 @@ export class NodeFlowExecutionService {
try {
logger.info(`🚀 플로우 실행 시작: flowId=${flowId}`);
// 🔍 디버깅: contextData 상세 로그
logger.info(`🔍 contextData 상세:`, {
directCompanyCode: contextData.companyCode,
nestedCompanyCode: contextData.context?.companyCode,
directUserId: contextData.userId,
nestedUserId: contextData.context?.userId,
contextKeys: Object.keys(contextData),
nestedContextKeys: contextData.context
? Object.keys(contextData.context)
: "no nested context",
});
// 1. 플로우 데이터 조회
const flow = await queryOne<{
flow_id: number;
@@ -979,12 +991,25 @@ export class NodeFlowExecutionService {
const userId = context.buttonContext?.userId;
const companyCode = context.buttonContext?.companyCode;
// 🔍 디버깅: 자동 추가 조건 확인
console.log(` 🔍 INSERT 자동 추가 조건 확인:`, {
hasWriterMapping,
hasCompanyCodeMapping,
userId,
companyCode,
buttonContext: context.buttonContext,
});
// writer 자동 추가 (매핑에 없고, 컨텍스트에 userId가 있는 경우)
if (!hasWriterMapping && userId) {
fields.push("writer");
values.push(userId);
insertedData.writer = userId;
console.log(` 🔧 자동 추가: writer = ${userId}`);
} else {
console.log(
` ⚠️ writer 자동 추가 스킵: hasWriterMapping=${hasWriterMapping}, userId=${userId}`
);
}
// company_code 자동 추가 (매핑에 없고, 컨텍스트에 companyCode가 있는 경우)
@@ -993,6 +1018,10 @@ export class NodeFlowExecutionService {
values.push(companyCode);
insertedData.company_code = companyCode;
console.log(` 🔧 자동 추가: company_code = ${companyCode}`);
} else {
console.log(
` ⚠️ company_code 자동 추가 스킵: hasCompanyCodeMapping=${hasCompanyCodeMapping}, companyCode=${companyCode}`
);
}
const sql = `
@@ -2251,6 +2280,34 @@ export class NodeFlowExecutionService {
values.push(value);
});
// 🆕 writer와 company_code 자동 추가 (필드 매핑에 없는 경우)
const hasWriterMapping = fieldMappings.some(
(m: any) => m.targetField === "writer"
);
const hasCompanyCodeMapping = fieldMappings.some(
(m: any) => m.targetField === "company_code"
);
// 컨텍스트에서 사용자 정보 추출
const userId = context.buttonContext?.userId;
const companyCode = context.buttonContext?.companyCode;
// writer 자동 추가 (매핑에 없고, 컨텍스트에 userId가 있는 경우)
if (!hasWriterMapping && userId) {
columns.push("writer");
values.push(userId);
logger.info(` 🔧 UPSERT INSERT - 자동 추가: writer = ${userId}`);
}
// company_code 자동 추가 (매핑에 없고, 컨텍스트에 companyCode가 있는 경우)
if (!hasCompanyCodeMapping && companyCode && companyCode !== "*") {
columns.push("company_code");
values.push(companyCode);
logger.info(
` 🔧 UPSERT INSERT - 자동 추가: company_code = ${companyCode}`
);
}
const placeholders = values.map((_, i) => `$${i + 1}`).join(", ");
const insertSql = `
INSERT INTO ${targetTable} (${columns.join(", ")})