Merge remote-tracking branch 'origin/iipbs/sn/dev' into iipbs/sn/dev

This commit is contained in:
2026-08-20 15:10:36 +09:00
11 changed files with 977 additions and 1062 deletions
@@ -0,0 +1,406 @@
"use client";
import { useCallback, useEffect, useMemo, useState } from "react";
import { Button } from "@common/components";
import { UiTable } from "@common/business_components/ui/table";
import type { UiHeadProps, UiTableSort } from "@common/business_components/ui";
import ListDiv from "@common/business_components/ui/list_div";
import { getBlobData, getRawJson } from "@/components/lib/api";
import { fileDownload } from "@/components/lib/utils/fileDownload";
import LoadingOverlay from "@/components/ui/LoadingBar";
import { WINDOW_POPUP_MESSAGE_TYPE } from "@/features/windowPopup/model/types";
import useStore from "@/store/useStore";
type ApiRow = {
sggCd: string;
ctpvCd: string;
ctpvNm: string;
sggNm: string;
rainBeginningDateTime: string;
analysisDateTime: string;
observedAccumulatedRainfall: number;
rainHour: number;
rainfall: number;
exceededFrequencyYear: number;
floodRiskGrade: string;
};
type TableRow = ApiRow & {
rowNo: number;
rainBeginningDateTimeDisplay: string;
analysisDateTimeDisplay: string;
observedAccumulatedRainfallDisplay: string;
rainHourDisplay: string;
rainfallDisplay: string;
exceededFrequencyYearDisplay: string;
};
type Filters = {
ctpvCd: string;
sggCd: string;
rainBgngFrom: string;
rainBgngTo: string;
analysisFrom: string;
analysisTo: string;
frequencyYear: string;
};
const PAGE_SIZE = 20;
const MAP_FREQUENCIES = new Set([30, 50, 80]);
const HEADS: UiHeadProps[] = [
{ id: "rowNo", title: "NO", widthPercent: 5, sortable: false },
{
id: "ctpvNm",
title: "시도",
widthPercent: 9,
sortable: true,
sortKey: "ctpvCd",
},
{
id: "sggNm",
title: "시군구",
widthPercent: 10,
sortable: true,
sortKey: "sggCd",
},
{
id: "rainBeginningDateTimeDisplay",
title: "강우 시작시각",
widthPercent: 13,
sortable: true,
sortKey: "rainBeginningDateTime",
},
{
id: "analysisDateTimeDisplay",
title: "분석시각",
widthPercent: 13,
sortable: true,
sortKey: "analysisDateTime",
},
{
id: "observedAccumulatedRainfallDisplay",
title: "관측 누적강수량(mm)",
widthPercent: 13,
sortable: true,
sortKey: "observedAccumulatedRainfall",
},
{
id: "rainHourDisplay",
title: "강우시간",
widthPercent: 9,
sortable: true,
sortKey: "rainHour",
},
{
id: "rainfallDisplay",
title: "강수량(mm)",
widthPercent: 10,
sortable: false,
},
{
id: "exceededFrequencyYearDisplay",
title: "초과빈도년도",
widthPercent: 9,
sortable: true,
sortKey: "exceededFrequencyYear",
},
{
id: "floodRiskGrade",
title: "위험등급",
widthPercent: 9,
sortable: true,
sortKey: "floodRiskGrade",
},
];
const localDateTime = (date: Date) =>
`${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(date.getDate()).padStart(2, "0")}T${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
const initialFilters = (): Filters => {
const now = new Date();
const from = new Date(now);
from.setHours(0, 0, 0, 0);
return {
ctpvCd: "0",
sggCd: "0",
// 최초 조회에서는 강우 시작시각을 제한하지 않고 전체 강우사상을 대상으로 한다.
rainBgngFrom: "",
rainBgngTo: "",
analysisFrom: localDateTime(from),
analysisTo: localDateTime(now),
frequencyYear: "",
};
};
const apiDate = (value: string) => value.replace(/[^0-9]/g, "").slice(0, 12);
const displayDate = (value: string) =>
/^\d{12}$/.test(value)
? `${value.slice(0, 4)}-${value.slice(4, 6)}-${value.slice(6, 8)} ${value.slice(8, 10)}:${value.slice(10, 12)}`
: value;
const rainHourText = (value: number) =>
value === 0 ? "현재" : `${value > 0 ? "+" : "-"}${Math.abs(value)}시간`;
const query = (filters: Filters, page?: number, sort?: UiTableSort) => {
const p = new URLSearchParams();
if (page !== undefined) {
p.set("page", String(page - 1));
p.set("size", String(PAGE_SIZE));
}
if (filters.ctpvCd !== "0") p.set("ctpvCd", filters.ctpvCd.slice(0, 2));
if (filters.sggCd !== "0") p.set("sggCd", filters.sggCd.slice(0, 5));
["rainBgngFrom", "rainBgngTo", "analysisFrom", "analysisTo"].forEach(
(key) => {
const value = apiDate(filters[key as keyof Filters]);
if (value) p.set(key, value);
},
);
if (filters.frequencyYear) p.set("frequencyYear", filters.frequencyYear);
if (sort?.key && sort.direction)
p.set("sort", `${sort.key},${sort.direction}`);
return p.toString();
};
export default function FldngPredcPrstPopupContent() {
const { ctpv, sgg, fetchCtpv, fetchSgg } = useStore();
const [filters, setFilters] = useState<Filters>(() => initialFilters());
const [applied, setApplied] = useState<Filters>(() => initialFilters());
const [rows, setRows] = useState<TableRow[]>([]);
const [total, setTotal] = useState(0);
const [page, setPage] = useState(1);
const [sort, setSort] = useState<UiTableSort>();
const [loading, setLoading] = useState(false);
const [selected, setSelected] = useState(-1);
useEffect(() => {
if (!ctpv.length) void fetchCtpv();
if (!sgg.length) void fetchSgg();
}, [ctpv.length, fetchCtpv, fetchSgg, sgg.length]);
const sggOptions = useMemo(
() =>
filters.ctpvCd === "0"
? sgg
: sgg.filter((item) =>
String(item.val).startsWith(filters.ctpvCd.slice(0, 2)),
),
[filters.ctpvCd, sgg],
);
const load = useCallback(
async (targetPage: number, condition: Filters, nextSort?: UiTableSort) => {
setLoading(true);
try {
const response = await getRawJson(
`/sewerage-service/api/v1/fldng/predc/prst?${query(condition, targetPage, nextSort)}`,
);
const payload = response?.data ?? response;
const content: ApiRow[] = Array.isArray(payload?.content)
? payload.content
: [];
setRows(
content.map((item, index) => ({
...item,
rowNo: (targetPage - 1) * PAGE_SIZE + index + 1,
rainBeginningDateTimeDisplay: displayDate(
item.rainBeginningDateTime,
),
analysisDateTimeDisplay: displayDate(item.analysisDateTime),
observedAccumulatedRainfallDisplay: Number(
item.observedAccumulatedRainfall ?? 0,
).toFixed(4),
rainHourDisplay: rainHourText(Number(item.rainHour ?? 0)),
rainfallDisplay: Number(item.rainfall ?? 0).toFixed(1),
exceededFrequencyYearDisplay: String(
item.exceededFrequencyYear ?? "",
),
})),
);
setTotal(Number(payload?.totalElements ?? 0));
setPage(targetPage);
setApplied(condition);
setSort(nextSort);
setSelected(-1);
} catch (error) {
console.error(error);
alert(
error instanceof Error
? error.message
: "침수예측현황 조회에 실패했습니다.",
);
} finally {
setLoading(false);
}
},
[],
);
useEffect(() => {
const defaults = initialFilters();
setFilters(defaults);
void load(1, defaults);
}, [load]);
const mapRow = async (index?: number) => {
if (typeof index !== "number") return;
const row = rows[index];
if (!row) return;
setSelected(index);
if (!MAP_FREQUENCIES.has(row.exceededFrequencyYear)) {
alert(
`${row.exceededFrequencyYear}년 빈도 도시침수지도는 제공되지 않습니다. (30·50·80년 빈도만 제공)`,
);
return;
}
setLoading(true);
try {
const sbmrgFrqExpln = `${row.exceededFrequencyYear}년`;
const p = new URLSearchParams({ sggCd: row.sggCd, sbmrgFrqExpln });
const extentData = await getRawJson(
`/sewerage-service/api/v1/fldng/flood-dngr-map/group/extent?${p}`,
);
const extent = [
extentData.minX,
extentData.minY,
extentData.maxX,
extentData.maxY,
].map(Number);
if (extent.some((v) => !Number.isFinite(v)))
throw new Error("도시침수지도 위치 정보가 없습니다.");
window.opener?.postMessage(
{
type: WINDOW_POPUP_MESSAGE_TYPE.MAP_SEARCH_SHOW_FLOOD_GROUP,
payload: { extent, sggCd: row.sggCd, sbmrgFrqExpln },
},
window.location.origin,
);
} catch (error) {
alert(
error instanceof Error ? error.message : "지도 이동에 실패했습니다.",
);
} finally {
setLoading(false);
}
};
const download = async () => {
if (!total) return alert("다운로드할 데이터가 없습니다.");
setLoading(true);
try {
const blob = await getBlobData(
`/sewerage-service/api/v1/fldng/predc/prst/excel?${query(applied, undefined, sort)}`,
);
fileDownload(blob, "침수예측현황.xlsx");
} catch (error) {
alert(
error instanceof Error
? error.message
: "Excel 다운로드에 실패했습니다.",
);
} finally {
setLoading(false);
}
};
const field = (key: keyof Filters, label: string) => (
<label className="sn-popup-field">
<div className="sn-popup-field-label">{label}</div>
<input
className="sn-popup-input"
type="datetime-local"
value={filters[key]}
onChange={(e) => setFilters((v) => ({ ...v, [key]: e.target.value }))}
/>
</label>
);
return (
<main className="sn-popup-page w-full max-w-full overflow-hidden">
<LoadingOverlay isLoading={loading} />
<header className="sn-popup-header">
<h1 className="sn-popup-title">침수예측현황</h1>
<div />
</header>
<section className="flex min-h-0 flex-1 flex-col px-4 pb-3 pt-3">
<div className="sn-popup-filter-panel-compact grid grid-cols-4 gap-3">
<label className="sn-popup-field">
<div className="sn-popup-field-label">시도</div>
<select
className="sn-popup-input"
value={filters.ctpvCd}
onChange={(e) =>
setFilters((v) => ({
...v,
ctpvCd: e.target.value,
sggCd: "0",
}))
}
>
<option value="0">전체</option>
{ctpv.map((x) => (
<option key={x.val} value={String(x.val)}>
{x.text}
</option>
))}
</select>
</label>
<label className="sn-popup-field">
<div className="sn-popup-field-label">시군구</div>
<select
className="sn-popup-input"
value={filters.sggCd}
onChange={(e) =>
setFilters((v) => ({ ...v, sggCd: e.target.value }))
}
>
<option value="0">전체</option>
{sggOptions.map((x) => (
<option key={x.val} value={String(x.val)}>
{x.text}
</option>
))}
</select>
</label>
{field("rainBgngFrom", "강우 시작시각 From")}
{field("rainBgngTo", "강우 시작시각 To")}
{field("analysisFrom", "분석시각 From")}
{field("analysisTo", "분석시각 To")}
<label className="sn-popup-field">
<div className="sn-popup-field-label">초과 빈도년도</div>
<input
className="sn-popup-input"
type="number"
min="0"
value={filters.frequencyYear}
onChange={(e) =>
setFilters((v) => ({ ...v, frequencyYear: e.target.value }))
}
/>
</label>
<div className="sn-popup-actions self-end">
<Button
size="sm"
color="primary"
onClick={() => void load(1, filters, sort)}
>
조회
</Button>
<Button size="sm" color="primary" onClick={() => void download()}>
다운로드
</Button>
</div>
</div>
<ListDiv className="mt-3 min-h-0 flex-1 overflow-x-auto">
<div className="min-w-[1450px]">
<UiTable<TableRow>
headName={
<>침수예측현황 조회 결과 총 {total.toLocaleString()}건</>
}
tableData={rows}
headlist={HEADS}
pageSize={PAGE_SIZE}
total={total}
curPage={page}
onPageChange={(p) => void load(p, applied, sort)}
cellClick={(i) => void mapRow(i)}
index={selected}
widthFixed={true}
isHideCount={true}
sort={sort}
onSortChange={(s) => void load(1, applied, s)}
/>
</div>
</ListDiv>
<div className="sn-popup-help-text">
행 클릭 시 해당 시군구·빈도의 도시침수지도로 이동합니다.
</div>
</section>
</main>
);
}
@@ -182,11 +182,11 @@ export const windowPopupDefinitions = {
height: 760,
requiredParams: ["zoneId"],
},
floodPredictionMapPopup: {
key: "floodPredictionMapPopup",
fldngPredcPrst: {
key: "fldngPredcPrst",
title: "침수예측현황",
width: 1080,
height: 760,
width: 1500,
height: 860,
},
agedPipeStatusByCtpvPopup: {
key: "agedPipeStatusByCtpvPopup",
@@ -223,8 +223,8 @@ export const windowPopupDefinitions = {
flowRiskPopup: {
key: "flowRiskPopup",
title: "통수 위험",
width: 1180,
height: 820,
width: 1360,
height: 600,
},
} as const satisfies Record<string, WindowPopupDefinition>;
+5 -10
View File
@@ -123,13 +123,8 @@ const RepairHistoryPopupContent = loadPopupContent(
const WaterRiskPopupContent = loadPopupContent(
() => import("./ui/WaterRiskPopupContent"),
);
const FloodPredictionPlaceholderPopupContent = (
_props: WindowPopupContentProps,
) => (
<FeaturePlaceholderPopupContent
title={windowPopupDefinitions.floodPredictionMapPopup.title}
/>
const FldngPredcPrstPopupContent = loadPopupContent(
() => import("../fldngPredcPrst/ui/FldngPredcPrstPopupContent"),
);
const GisEditPopupContent = (_props: WindowPopupContentProps) => (
@@ -243,9 +238,9 @@ export const windowPopupRegistry = {
...windowPopupDefinitions.repairHistoryPopup,
component: RepairHistoryPopupContent,
},
floodPredictionMapPopup: {
...windowPopupDefinitions.floodPredictionMapPopup,
component: FloodPredictionPlaceholderPopupContent,
fldngPredcPrst: {
...windowPopupDefinitions.fldngPredcPrst,
component: FldngPredcPrstPopupContent,
},
agedPipeStatusByCtpvPopup: {
...windowPopupDefinitions.agedPipeStatusByCtpvPopup,