124 lines
5.0 KiB
TypeScript
124 lines
5.0 KiB
TypeScript
import { useRef, useState } from "react";
|
|
|
|
import { useAlertStore } from "@/shared/lib";
|
|
import { LoadingWithAnimation } 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";
|
|
|
|
// 분리된 중계펌프장용 컬럼 구성 임포트
|
|
import { MediationPumpStatusColumnConfig } from "@/components/util/column/total/SewerMediationPumpStatusColumn";
|
|
|
|
// 집계표(TOTAL) API 및 인터페이스 명세 호출
|
|
import { statisticsTotalStatusApi } from "@/entities/statistics/api/statistics-total-service";
|
|
import type {
|
|
MediationPumpMaintainTotalRequest
|
|
} from "@/entities/statistics/model/statistics-total/statistics-mediation-pump-total-interface";
|
|
import CellColorInfo from "./CellColorInfo";
|
|
|
|
const PumpingStationTot = () => {
|
|
const { setMessage: alert } = useAlertStore((state) => state);
|
|
|
|
// null 타입 컴파일 에러가 발생하지 않도록 엄격하게 정의한 데이터 상태
|
|
const [rowData, setRowData] = useState<Record<string, string | number>[]>([]);
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
const lastSearchedValuesRef = useRef<SearchFormValues | null>(null);
|
|
|
|
const config = MediationPumpStatusColumnConfig;
|
|
|
|
const handleReset = () => {
|
|
setRowData([]);
|
|
lastSearchedValuesRef.current = null;
|
|
};
|
|
|
|
const loadGridData = async (values: SearchFormValues): Promise<boolean> => {
|
|
const param: MediationPumpMaintainTotalRequest = {
|
|
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 {
|
|
const response = await statisticsTotalStatusApi.getMediationPumpStationStatusTotalList(param);
|
|
if (response && response.status === "success" && response.data) {
|
|
// object[]로 변환하여 주입함으로써 null 에러 전면 방지
|
|
setRowData(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(values);
|
|
if (ok) {
|
|
lastSearchedValuesRef.current = values;
|
|
} else {
|
|
lastSearchedValuesRef.current = null;
|
|
}
|
|
} catch {
|
|
alert("데이터 조회 중 오류가 발생했습니다.");
|
|
lastSearchedValuesRef.current = null;
|
|
} finally {
|
|
setIsLoading(false);
|
|
}
|
|
};
|
|
|
|
const gridColumnInfo: ColumnInfo = {
|
|
columns: config.columns,
|
|
columnLayout: config.columnLayout,
|
|
};
|
|
|
|
return (
|
|
<div className="relative">
|
|
<SearchForm isDetail={true} isSummary={true} onSubmit={handleSearch} onReset={handleReset} sidoSelectText="전체" />
|
|
|
|
{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] mt-[0.6rem]">
|
|
<DataGrid
|
|
columnInfo={gridColumnInfo}
|
|
rowStartNum={config.rowStartNum}
|
|
excelExportFileSuffix={config.tabLabel}
|
|
rowData={rowData}
|
|
setRowData={setRowData}
|
|
isExcelImport={false}
|
|
isExcelExport={true}
|
|
showHeaderCheckbox={false}
|
|
fixedColumns={config.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';
|
|
}}
|
|
/>
|
|
</div>
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default PumpingStationTot; |