merge: resolve conflicts accepting incoming changes

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
kjs
2026-04-07 14:44:17 +09:00
23 changed files with 6621 additions and 2901 deletions

View File

@@ -7,6 +7,7 @@ import { JwtUtils } from "../utils/jwtUtils";
import { LoginRequest, UserInfo, ApiResponse, PersonBean } from "../types/auth";
import { logger } from "../utils/logger";
import { sendSmartFactoryLog } from "../utils/smartFactoryLog";
import { query, queryOne } from "../database/db";
export class AuthController {
/**
@@ -105,6 +106,14 @@ export class AuthController {
popLandingPath = "/pop";
}
logger.debug(`POP 랜딩 경로: ${popLandingPath}`);
// POP 메뉴가 존재하면 해당 회사의 POP 레이아웃 자동 초기화 (비동기)
if (popLandingPath) {
const companyCode = loginResult.userInfo.companyCode || "ILSHIN";
AuthController.initPopLayoutsForCompany(companyCode).catch((err) => {
logger.warn("POP 레이아웃 자동 초기화 중 오류 (무시):", err);
});
}
} catch (popError) {
logger.warn("POP 메뉴 조회 중 오류 (무시):", popError);
}
@@ -563,4 +572,78 @@ export class AuthController {
});
}
}
/**
* POP 레이아웃 자동 초기화
* 해당 회사의 screen_layouts_pop 레코드가 없으면
* 템플릿(공통 '*' 또는 COMPANY_7)에서 복제하여 생성
*
* 기본 POP 화면 ID: 5, 6, 7, 8, 6526, 6527, 6528, 6529
*/
static async initPopLayoutsForCompany(companyCode: string): Promise<void> {
// SUPER_ADMIN이나 공통(*)은 초기화 불필요
if (companyCode === "*" || companyCode === "COMPANY_7") return;
const POP_SCREEN_IDS = [5, 6, 7, 8, 6526, 6527, 6528, 6529];
// 이미 해당 회사의 POP 레이아웃이 하나라도 있으면 스킵 (중복 초기화 방지)
const existing = await query<{ cnt: string }>(
`SELECT COUNT(*)::text AS cnt FROM screen_layouts_pop
WHERE company_code = $1 AND screen_id = ANY($2::int[])`,
[companyCode, POP_SCREEN_IDS],
);
const existingCount = parseInt(existing[0]?.cnt || "0", 10);
if (existingCount > 0) {
logger.debug(`POP 레이아웃 이미 존재 (${companyCode}): ${existingCount}개, 스킵`);
return;
}
logger.info(`POP 레이아웃 자동 초기화 시작: ${companyCode}`);
// 회사명 조회 (레이아웃 내 회사명 치환용)
const companyInfo = await queryOne<{ company_name: string }>(
`SELECT company_name FROM company_mng WHERE company_code = $1`,
[companyCode],
);
const companyName = companyInfo?.company_name || companyCode;
let initCount = 0;
for (const screenId of POP_SCREEN_IDS) {
// 템플릿 조회: 공통(*) 우선, 없으면 COMPANY_7 폴백
let template = await queryOne<{ layout_data: any }>(
`SELECT layout_data FROM screen_layouts_pop
WHERE screen_id = $1 AND company_code = '*'`,
[screenId],
);
if (!template) {
template = await queryOne<{ layout_data: any }>(
`SELECT layout_data FROM screen_layouts_pop
WHERE screen_id = $1 AND company_code = 'COMPANY_7'`,
[screenId],
);
}
if (!template) {
logger.debug(`POP 템플릿 없음 (screen_id=${screenId}), 스킵`);
continue;
}
// 레이아웃 복제 + 회사명 치환
const layoutStr = JSON.stringify(template.layout_data);
const replacedStr = layoutStr
.replace(/\(주\)탑씰/g, companyName)
.replace(/탑씰/g, companyName)
.replace(/TOPSEAL/gi, companyName);
await query(
`INSERT INTO screen_layouts_pop (screen_id, company_code, layout_data, created_at, updated_at, created_by, updated_by)
VALUES ($1, $2, $3, NOW(), NOW(), 'SYSTEM', 'SYSTEM')
ON CONFLICT (screen_id, company_code) DO NOTHING`,
[screenId, companyCode, replacedStr],
);
initCount++;
}
logger.info(`POP 레이아웃 자동 초기화 완료: ${companyCode}, ${initCount}개 화면`);
}
}