[st] - fix: 2-3 컬럼 로직 수정, 입력단 excel 업로드 시 행정동코드 매핑 검사
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import type {
|
||||
ColumnConfig,
|
||||
ColumnLayoutItem,
|
||||
ExcelExportSearchContext,
|
||||
} from "@/components/type/DataGrid.type";
|
||||
import type { GridView } from "realgrid";
|
||||
|
||||
@@ -33,6 +34,27 @@ export type ExcelImportColumnFieldNamesOptions = {
|
||||
skipNonEditable?: boolean;
|
||||
};
|
||||
|
||||
const ADMDST_CD_FIELD = "admdstCd";
|
||||
|
||||
export function hasAdmdstCdColumn(columns: ColumnConfig[]): boolean {
|
||||
return columns.some((col) => col.fieldName === ADMDST_CD_FIELD);
|
||||
}
|
||||
|
||||
/** 엑셀에서 읽은 admdstCd만 검증 — 빈 값 또는 sewerBzmnCd 앞 2자리 불일치 시 true(실패) */
|
||||
export function isExcelImportAdmdstCdInvalid(
|
||||
sewerBzmnCd: string | null | undefined,
|
||||
admdstCdFromExcel: ReadonlyArray<string | number | undefined>,
|
||||
): boolean {
|
||||
const expectedPrefix = sewerBzmnCd?.trim().slice(0, 2) ?? "";
|
||||
if (expectedPrefix.length < 2) return false;
|
||||
|
||||
return admdstCdFromExcel.some((raw) => {
|
||||
const admdstCd = String(raw ?? "").trim();
|
||||
if (!admdstCd) return true;
|
||||
return admdstCd.slice(0, 2) !== expectedPrefix;
|
||||
});
|
||||
}
|
||||
|
||||
/** 엑셀 가져오기 — N번째 열을 그리드 N번째 fieldName에 매핑 (보내기 컬럼 순서와 동일) */
|
||||
export function getExcelImportColumnFieldNames(
|
||||
columns: ColumnConfig[],
|
||||
@@ -170,3 +192,46 @@ export function restoreGridColumnsAfterExcelExport(
|
||||
export function shouldPrepareColumnsForExcelExport(columns: ColumnConfig[]): boolean {
|
||||
return columns.some((c) => c.excludeFromExcelExport || c.visible === false);
|
||||
}
|
||||
|
||||
const INVALID_EXCEL_FILE_NAME_CHARS = /[\\/:*?"<>|]/g;
|
||||
|
||||
function sanitizeExcelFileNamePart(value: string): string {
|
||||
return value.replace(INVALID_EXCEL_FILE_NAME_CHARS, "").trim();
|
||||
}
|
||||
|
||||
/** 엑셀 파일명: `{메뉴명}_{탭접미사}_{시도}_{시군구}_{연도}` */
|
||||
export function buildExcelExportFileBaseName(
|
||||
menuName: string,
|
||||
tabSuffix?: string,
|
||||
searchContext?: ExcelExportSearchContext | null,
|
||||
): string {
|
||||
const parts: string[] = [sanitizeExcelFileNamePart(menuName)];
|
||||
|
||||
if (tabSuffix?.trim()) {
|
||||
parts.push(sanitizeExcelFileNamePart(tabSuffix.trim()));
|
||||
}
|
||||
|
||||
const ctpvNm = searchContext?.ctpvNm?.trim();
|
||||
const sggNm = searchContext?.sggNm?.trim();
|
||||
const statsYr = searchContext?.statsYr?.trim();
|
||||
|
||||
if (ctpvNm) parts.push(sanitizeExcelFileNamePart(ctpvNm));
|
||||
if (sggNm && sggNm !== "ALL") parts.push(sanitizeExcelFileNamePart(sggNm));
|
||||
if (statsYr) parts.push(sanitizeExcelFileNamePart(statsYr));
|
||||
|
||||
return parts.filter(Boolean).join("_");
|
||||
}
|
||||
|
||||
export function toExcelExportSearchContextFromSearchForm(
|
||||
values: { sido?: string; gugun?: string; year?: string } | null | undefined,
|
||||
): ExcelExportSearchContext | undefined {
|
||||
if (!values) return undefined;
|
||||
|
||||
const ctpvNm = values.sido?.trim();
|
||||
const sggNm = values.gugun === "ALL" ? "" : (values.gugun?.trim() ?? "");
|
||||
const statsYr = values.year?.trim();
|
||||
|
||||
if (!ctpvNm && !sggNm && !statsYr) return undefined;
|
||||
|
||||
return { ctpvNm, sggNm, statsYr };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user