diff --git a/apps/st/src/components/statistics/total/SewagePipeTot.tsx b/apps/st/src/components/statistics/total/SewagePipeTot.tsx index 061405229..08aac9eb0 100644 --- a/apps/st/src/components/statistics/total/SewagePipeTot.tsx +++ b/apps/st/src/components/statistics/total/SewagePipeTot.tsx @@ -8,7 +8,7 @@ import SearchForm from "@/components/module/SearchForm"; import DataGrid from "@/components/module/DataGrid"; import type { ColumnInfo } from "@/components/type/DataGrid.type"; import type { SearchFormValues } from "@/components/type/SearchForm.type"; -import { SewagePipeColumnInfoListTot } from "@/components/util/column/total/SewagePipeTotColumn"; +import { SewagePipeColumnInfoListTot, getST00020003Config } from "@/components/util/column/total/SewagePipeTotColumn"; import { toGridRows } from "@/components/util/grid/gridFunction"; import type { SewagePipeTotalRequest } from "@/entities/statistics/model/statistics-total/statistics-sewage-pipe-total-interface"; import CellColorInfo from "./CellColorInfo"; @@ -46,7 +46,6 @@ const SewagePipeTot = () => { lastSearchedValuesRef.current = null; }; - /** SewagePipeInp의 `loadSewagePipeActiveTabData`와 동일 역할: 탭키별 API 호출 후 `rowDataMap` 반영 */ const loadSewagePipeTotTabData = async ( tabKey: string, values: SearchFormValues, @@ -107,7 +106,8 @@ const SewagePipeTot = () => { alert(response.message || "데이터 조회 중 오류가 발생했습니다."); return false; } - if (tabKey === "ST00020005") { + + if (tabKey === "ST00020005") { const response = await statisticsTotalStatusApi.getSewagePipePipeMnhleStatus(param); if (response.status === "success" && response.data) { applyRows(toGridRows(response.data as object[])); @@ -124,7 +124,6 @@ const SewagePipeTot = () => { try { setIsLoading(true); - // SewagePipeInp과 동일: 검색 시 활성 탭 데이터만 조회·맵 병합 let ok = false; if ( activeTab === "ST00020001" || @@ -175,8 +174,6 @@ const SewagePipeTot = () => { } return; } - - console.log("[SewagePipeTot] tabKey (API 미연결):", tabKey); }; return ( @@ -206,22 +203,29 @@ const SewagePipeTot = () => { {columnInfo.map((info) => { const tabKey = info.tabKey; - if (!info.columns || !info.columnLayout) { + + // ★ [동적 처리] ST00020003인 경우 함수를 통해 컬럼 정보를 실시간으로 생성 + const currentYear = lastSearchedValuesRef.current?.year || new Date().getFullYear(); + const finalTabConfig = tabKey === "ST00020003" + ? getST00020003Config(currentYear) + : info; + + if (!finalTabConfig.columns || !finalTabConfig.columnLayout) { return null; } const rowData = rowDataMap.get(tabKey) ?? []; const gridColumnInfo: ColumnInfo = { - columns: info.columns, - columnLayout: info.columnLayout, + columns: finalTabConfig.columns, + columnLayout: finalTabConfig.columnLayout, }; return ( { setRowDataMap((prev) => { @@ -236,7 +240,7 @@ const SewagePipeTot = () => { isExcelImport={false} isExcelExport showHeaderCheckbox={false} - fixedColumns={info.fixedColumns} + fixedColumns={finalTabConfig.fixedColumns} enableSort={false} cellStyleCallback={({ row }) => { const rowType = String(row.rowType ?? ''); @@ -255,4 +259,4 @@ const SewagePipeTot = () => { ); }; -export default SewagePipeTot; +export default SewagePipeTot; \ No newline at end of file diff --git a/apps/st/src/components/util/column/total/SewagePipeTotColumn.ts b/apps/st/src/components/util/column/total/SewagePipeTotColumn.ts index e2a30d9e0..cfb46b13f 100644 --- a/apps/st/src/components/util/column/total/SewagePipeTotColumn.ts +++ b/apps/st/src/components/util/column/total/SewagePipeTotColumn.ts @@ -605,103 +605,6 @@ const rawSewagePipeTotList = [ }, ], }, - - { - tabKey: "ST00020003", - tabLabel: "관종별 현황", - rowStartNum: 2, - fixedColumns: 2, - columns: [ - { name: "ctpvNm", fieldName: "ctpvNm", header: { text: "시도" }, editable: false }, - { name: "sggNm", fieldName: "sggNm", header: { text: "시군구" }, editable: false }, - { name: "admdstNm", fieldName: "admdstNm", header: { text: "행정구역명" }, editable: false }, - { name: "swrgPipeNm", fieldName: "swrgPipeNm", header: { text: "관종" }, editable: false }, - { - name: "pipeByPrstWholSum", - fieldName: "pipeByPrstWhol", - header: { text: "계" }, - valueType: ValueType.NUMBER, - dataFormat: "#,##0.0", - editable: false, - }, - { - name: "lyngPrlgSum", - fieldName: "lyngPrlg", - header: { text: "매설연장(m)" }, - valueType: ValueType.NUMBER, - dataFormat: "#,##0.0", - editable: false, - }, - { - name: "dmltnPrlgSum", - fieldName: "dmltnPrlg", - header: { text: "철거연장(m)" }, - valueType: ValueType.NUMBER, - dataFormat: "#,##0.0", - editable: false, - }, - ...Array.from({ length: YY_PIPE_TYPE_FACILITY_MAX }, (_, i) => { - const yyIdx = i + 1; - const wholField = `yy${yyIdx}PrlgWhol`; - const lyngField = `yy${yyIdx}LyngPrlg`; - const dmltnField = `yy${yyIdx}DmltnPrlg`; - return [ - { - name: wholField, - fieldName: wholField, - header: { text: "계" }, - valueType: ValueType.NUMBER, - dataFormat: "#,##0.0", - editable: false, - }, - { - name: lyngField, - fieldName: lyngField, - header: { text: "매설연장(m)" }, - valueType: ValueType.NUMBER, - dataFormat: "#,##0.0", - editable: false, - }, - { - name: dmltnField, - fieldName: dmltnField, - header: { text: "철거연장(m)" }, - valueType: ValueType.NUMBER, - dataFormat: "#,##0.0", - editable: false, - }, - ]; - }).flat(), - ], - columnLayout: [ - { - name: "areaGroup", - header: { text: "행정구역" }, - items: ["ctpvNm", "sggNm", "admdstNm"], - }, - "swrgPipeNm", - { - name: "summaryGroup", - header: { text: "총계" }, - items: ["pipeByPrstWholSum", "lyngPrlgSum", "dmltnPrlgSum"], - }, - { - name: "year1996Before", - header: { text: "1996년이전" }, - items: ["yy1PrlgWhol", "yy1LyngPrlg", "yy1DmltnPrlg"], - }, - ...Array.from({ length: YY_PIPE_TYPE_FACILITY_MAX - 1 }, (_, i) => { - const yyIdx = i + 2; - const year = 1994 + yyIdx; - return { - name: `group_yy${yyIdx}`, - header: { text: `${year}년` }, - items: [`yy${yyIdx}PrlgWhol`, `yy${yyIdx}LyngPrlg`, `yy${yyIdx}DmltnPrlg`], - }; - }), - ], - }, - { tabKey: "ST00020004", tabLabel: "관경별 현황", @@ -1019,13 +922,70 @@ const rawSewagePipeTotList = [ ], }, "rmrk", -], + ], }, - + ]; +// 2. 동적 컬럼(ST00020003) 생성 함수 +export const getST00020003Config = (statsYr: string | number) => { + const startYear = 1995; + const endYear = Number(statsYr) || new Date().getFullYear(); + + return { + tabKey: "ST00020003", + tabLabel: "관종별 현황", + rowStartNum: 2, + fixedColumns: 2, + columns: [ + { name: "ctpvNm", fieldName: "ctpvNm", header: { text: "시도" }, editable: false }, + { name: "sggNm", fieldName: "sggNm", header: { text: "시군구" }, editable: false }, + { name: "admdstNm", fieldName: "admdstNm", header: { text: "행정구역명" }, editable: false }, + { name: "swrgPipeNm", fieldName: "swrgPipeNm", header: { text: "관종" }, editable: false }, + { name: "pipeByPrstWholSum", fieldName: "pipeByPrstWhol", header: { text: "계" }, valueType: ValueType.NUMBER, dataFormat: "#,##0.0", editable: false }, + { name: "lyngPrlgSum", fieldName: "lyngPrlg", header: { text: "매설연장(m)" }, valueType: ValueType.NUMBER, dataFormat: "#,##0.0", editable: false }, + { name: "dmltnPrlgSum", fieldName: "dmltnPrlg", header: { text: "철거연장(m)" }, valueType: ValueType.NUMBER, dataFormat: "#,##0.0", editable: false }, + ...(() => { + const yearColumns = []; + for (let yr = startYear; yr <= endYear; yr++) { + yearColumns.push( + { name: `prlg_whol_${yr}`, fieldName: `prlg_whol_${yr}`, header: { text: "계" }, valueType: ValueType.NUMBER, dataFormat: "#,##0.0", editable: false }, + { name: `lyng_prlg_${yr}`, fieldName: `lyng_prlg_${yr}`, header: { text: "매설연장(m)" }, valueType: ValueType.NUMBER, dataFormat: "#,##0.0", editable: false }, + { name: `dmltn_prlg_${yr}`, fieldName: `dmltn_prlg_${yr}`, header: { text: "철거연장(m)" }, valueType: ValueType.NUMBER, dataFormat: "#,##0.0", editable: false } + ); + } + return yearColumns; + })(), + ], + columnLayout: [ + { name: "areaGroup", header: { text: "행정구역" }, items: ["ctpvNm", "sggNm", "admdstNm"] }, + "swrgPipeNm", + { name: "summaryGroup", header: { text: "총계" }, items: ["pipeByPrstWholSum", "lyngPrlgSum", "dmltnPrlgSum"] }, + ...(() => { + const layouts = []; + for (let yr = startYear; yr <= endYear; yr++) { + layouts.push({ + name: `group_${yr}`, + header: { text: yr === 1995 ? "1996년이전" : `${yr}년` }, + items: [`prlg_whol_${yr}`, `lyng_prlg_${yr}`, `dmltn_prlg_${yr}`], + }); + } + return layouts; + })(), + ], + }; +}; + export const SewagePipeColumnInfoListTot = rawSewagePipeTotList.map((tab) => ({ ...tab, columns: tab.columns.map((col) => ({ ...col, editable: false as const })), })); +SewagePipeColumnInfoListTot.splice(2, 0, { + tabKey: "ST00020003", + tabLabel: "관종별 현황", + rowStartNum: 2, + fixedColumns: 2, + columns: [], + columnLayout: [], +} as any); \ No newline at end of file diff --git a/apps/st/src/entities/statistics/model/statistics-total/statistics-sewage-pipe-total-interface.ts b/apps/st/src/entities/statistics/model/statistics-total/statistics-sewage-pipe-total-interface.ts index 8643d41d6..76132a1ac 100644 --- a/apps/st/src/entities/statistics/model/statistics-total/statistics-sewage-pipe-total-interface.ts +++ b/apps/st/src/entities/statistics/model/statistics-total/statistics-sewage-pipe-total-interface.ts @@ -102,99 +102,7 @@ export interface SewagePipeFactInstallStatusResponse { /** ST00020003 합계 — `GET .../sewer-pipe/pipe-type-facility-status` */ export interface SewagePipePipeTypeFacilityStatusItem { - pipeByPrstWhol: number; - lyngPrlg: number; - dmltnPrlg: number; - yy1PrlgWhol: number; - yy1LyngPrlg: number; - yy1DmltnPrlg: number; - yy2PrlgWhol: number; - yy2LyngPrlg: number; - yy2DmltnPrlg: number; - yy3PrlgWhol: number; - yy3LyngPrlg: number; - yy3DmltnPrlg: number; - yy4PrlgWhol: number; - yy4LyngPrlg: number; - yy4DmltnPrlg: number; - yy5PrlgWhol: number; - yy5LyngPrlg: number; - yy5DmltnPrlg: number; - yy6PrlgWhol: number; - yy6LyngPrlg: number; - yy6DmltnPrlg: number; - yy7PrlgWhol: number; - yy7LyngPrlg: number; - yy7DmltnPrlg: number; - yy8PrlgWhol: number; - yy8LyngPrlg: number; - yy8DmltnPrlg: number; - yy9PrlgWhol: number; - yy9LyngPrlg: number; - yy9DmltnPrlg: number; - yy10PrlgWhol: number; - yy10LyngPrlg: number; - yy10DmltnPrlg: number; - yy11PrlgWhol: number; - yy11LyngPrlg: number; - yy11DmltnPrlg: number; - yy12PrlgWhol: number; - yy12LyngPrlg: number; - yy12DmltnPrlg: number; - yy13PrlgWhol: number; - yy13LyngPrlg: number; - yy13DmltnPrlg: number; - yy14PrlgWhol: number; - yy14LyngPrlg: number; - yy14DmltnPrlg: number; - yy15PrlgWhol: number; - yy15LyngPrlg: number; - yy15DmltnPrlg: number; - yy16PrlgWhol: number; - yy16LyngPrlg: number; - yy16DmltnPrlg: number; - yy17PrlgWhol: number; - yy17LyngPrlg: number; - yy17DmltnPrlg: number; - yy18PrlgWhol: number; - yy18LyngPrlg: number; - yy18DmltnPrlg: number; - yy19PrlgWhol: number; - yy19LyngPrlg: number; - yy19DmltnPrlg: number; - yy20PrlgWhol: number; - yy20LyngPrlg: number; - yy20DmltnPrlg: number; - yy21PrlgWhol: number; - yy21LyngPrlg: number; - yy21DmltnPrlg: number; - yy22PrlgWhol: number; - yy22LyngPrlg: number; - yy22DmltnPrlg: number; - yy23PrlgWhol: number; - yy23LyngPrlg: number; - yy23DmltnPrlg: number; - yy24PrlgWhol: number; - yy24LyngPrlg: number; - yy24DmltnPrlg: number; - yy25PrlgWhol: number; - yy25LyngPrlg: number; - yy25DmltnPrlg: number; - yy26PrlgWhol: number; - yy26LyngPrlg: number; - yy26DmltnPrlg: number; - yy27PrlgWhol: number; - yy27LyngPrlg: number; - yy27DmltnPrlg: number; - yy28PrlgWhol: number; - yy28LyngPrlg: number; - yy28DmltnPrlg: number; - yy29PrlgWhol: number; - yy29LyngPrlg: number; - yy29DmltnPrlg: number; - yy30PrlgWhol: number; - yy30LyngPrlg: number; - yy30DmltnPrlg: number; + // 고정 필드 ctpvNm: string; sggNm: string | null; admdstCd: string; @@ -203,7 +111,19 @@ export interface SewagePipePipeTypeFacilityStatusItem { statsYr: string; rowType: string; rmrk: string | null; -} + + // 총계 필드 + pipeByPrstWhol: number; + lyngPrlg: number; + dmltnPrlg: number; + + /** + * 연도별 동적 데이터 필드 + "prlg_whol_1995", "lyng_prlg_1995", "dmltn_prlg_1995", + + */ + [key: string]: string | number | null; +} export interface SewagePipePipeTypeFacilityStatusResponse { status: string;