feat:[집계표]08.개인하수처리시설

This commit is contained in:
yangsein
2026-06-15 00:52:54 +09:00
parent 3c701359fd
commit a11eaf031d
5 changed files with 474 additions and 3 deletions
@@ -1,10 +1,206 @@
import { useRef, useState } from "react";
import { useAlertStore } from "@/shared/lib";
import { LoadingWithAnimation, Tabs, TabsContent, TabsList, TabsTrigger } from "@common/components";
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 { toGridRows } from "@/components/util/grid/gridFunction";
// 분리된 개별 3개 컬럼 스펙 파일 로드
import { PrivateSewageTab1ColumnConfig } from "@/components/util/column/total/sewerPrivateSewageColumn/SewerPrivateSewageTab1Column";
import { PrivateSewageTab2ColumnConfig } from "@/components/util/column/total/sewerPrivateSewageColumn/SewerPrivateSewageTab2Column";
import { PrivateSewageTab3ColumnConfig } from "@/components/util/column/total/sewerPrivateSewageColumn/SewerPrivateSewageTab3Column";
// 통계 API 서비스 및 통합 DTO 명세 임포트
import { statisticsTotalStatusApi } from "@/entities/statistics/api/statistics-total-service";
import type {
PrivateSewageFacilitySummaryRequest
} from "@/entities/statistics/model/statistics-total/statistics-private-sewage-total-interface";
import CellColorInfo from "./CellColorInfo";
const PrivateSewageColumnListTot = [
PrivateSewageTab1ColumnConfig,
PrivateSewageTab2ColumnConfig,
PrivateSewageTab3ColumnConfig
];
const firstTabKey = PrivateSewageColumnListTot[0]?.tabKey ?? "ST00040005_1";
const PrivateSewageFacilityTot = () => {
const { setMessage: alert } = useAlertStore((state) => state);
// null 컴파일 예러를 사전에 원천 차단한 안전 상태 맵 선언
const [rowDataMap, setRowDataMap] = useState<Map<string, Record<string, string | number>[]>>(new Map());
const [isLoading, setIsLoading] = useState(false);
const [activeTab, setActiveTab] = useState(firstTabKey);
const lastSearchedValuesRef = useRef<SearchFormValues | null>(null);
const columnInfo = PrivateSewageColumnListTot;
const handleReset = () => {
setRowDataMap(new Map());
setActiveTab(firstTabKey);
lastSearchedValuesRef.current = null;
};
/** 각 탭별 엔드포인트 비동기 디스패치 및 연동 */
const loadGridData = async (tabKey: string, values: SearchFormValues): Promise<boolean> => {
const param: PrivateSewageFacilitySummaryRequest = {
ctpvNm: values.sido === "ALL" ? "" : values.sido,
sggNm: values.gugun === "ALL" ? "" : values.gugun,
sewerBzmnCd: values.bsnmCd,
statsYr: values.year,
rowDataYn: values.isDetail,
summaryYn: values.isSummary !== 'ALL',
summaryYearCnt: values.isSummary !== 'ALL' ? Number(values.isSummary) : undefined
};
try {
// [Tab1] 처리용량별 오수처리시설
if (tabKey === "ST00080001") {
const response = await statisticsTotalStatusApi.getPrivateSewageTab1List(param);
if (response && response.status === "success" && response.data) {
setRowDataMap((prev) => new Map(prev).set(tabKey, toGridRows(response.data as object[])));
return true;
}
alert(response?.message || "데이터 조회 중 오류가 발생했습니다.");
}
// [Tab2] 정화조현황
if (tabKey === "ST00080002") {
const response = await statisticsTotalStatusApi.getPrivateSewageTab2List(param);
if (response && response.status === "success" && response.data) {
setRowDataMap((prev) => new Map(prev).set(tabKey, toGridRows(response.data as object[])));
return true;
}
alert(response?.message || "데이터 조회 중 오류가 발생했습니다.");
}
// [Tab3] 개인하수도 관리지역 지정공고 현황
if (tabKey === "ST00080003") {
const response = await statisticsTotalStatusApi.getPrivatePrivateMgmtAreaList(param);
if (response && response.status === "success" && response.data) {
setRowDataMap((prev) => new Map(prev).set(tabKey, toGridRows(response.data as object[])));
return true;
}
alert(response?.message || "데이터 조회 중 오류가 발생했습니다.");
}
return false;
} catch {
alert("서버 연결 중 오류가 발생했습니다.");
return false;
}
};
const handleSearch = async (values: SearchFormValues) => {
try {
setIsLoading(true);
const ok = await loadGridData(activeTab, values);
if (ok) {
lastSearchedValuesRef.current = values;
} else {
lastSearchedValuesRef.current = null;
}
} catch {
alert("데이터 조회 중 오류가 발생했습니다.");
lastSearchedValuesRef.current = null;
} finally {
setIsLoading(false);
}
};
const handleActiveTabChange = async (tabKey: string) => {
setActiveTab(tabKey);
const values = lastSearchedValuesRef.current;
if (!values) return;
const existing = rowDataMap.get(tabKey);
if (existing && existing.length > 0) return; // 캐싱 검증 스킵
try {
setIsLoading(true);
await loadGridData(tabKey, values);
} catch {
alert("데이터 조회 중 오류가 발생했습니다.");
} finally {
setIsLoading(false);
}
};
return (
<>
<SearchForm />
</>
<div className="relative">
<SearchForm isDetail={true} isSummary={true} onSubmit={handleSearch} onReset={handleReset} sidoSelectText="전체" />
{/* 하수관로 규칙과 100% 싱크 맞춘 중앙 정렬 소형 팝업 로딩 바 고정 */}
{isLoading && (
<div className="absolute inset-0 z-50 [data-theme='black']:bg-transparent rounded-lg p-10 flex justify-center items-center">
<div className="relative size-[5rem]">
<LoadingWithAnimation color="primary" />
</div>
</div>
)}
<CellColorInfo />
<div className="flex flex-col gap-[0.6rem] mx-[0.6rem]">
<Tabs value={activeTab} onValueChange={(v) => void handleActiveTabChange(v)} className="w-full" variant="default">
<TabsList>
{columnInfo.map((info) => (
<TabsTrigger key={info.tabKey} value={info.tabKey}>
{info.tabLabel}
</TabsTrigger>
))}
</TabsList>
{columnInfo.map((info) => {
const tabKey = info.tabKey;
// 단언 연산자(as) 배제 형태 완벽 적용
const rowData = rowDataMap.get(tabKey) ?? [];
const gridColumnInfo: ColumnInfo = {
columns: info.columns,
columnLayout: info.columnLayout,
};
return (
<TabsContent key={tabKey} value={tabKey}>
<DataGrid
columnInfo={gridColumnInfo}
rowStartNum={info.rowStartNum}
excelExportFileSuffix={info.tabLabel}
rowData={rowData}
setRowData={(updater) => {
setRowDataMap((prev) => {
const next = new Map(prev);
const cur = next.get(tabKey) ?? [];
const n = typeof updater === "function" ? updater(cur) : updater;
next.set(tabKey, n);
return next;
});
}}
isExcelImport={false}
isExcelExport={true}
showHeaderCheckbox={false}
fixedColumns={info.fixedColumns}
enableSort={false}
cellStyleCallback={({ row }) => {
const rowType = String(row.rowType ?? '');
if (rowType === 'DETAIL') return undefined;
if (rowType === 'BIZ_SUM') return 'rg-cell-rowtype-biz-sum';
if (rowType === 'SUMMARY') return 'rg-cell-rowtype-summary';
return 'rg-cell-rowtype-other';
}}
/>
</TabsContent>
);
})}
</Tabs>
</div>
</div>
);
};