대민 수요정보등록 기능 수정

This commit is contained in:
2026-04-01 17:03:16 +09:00
parent 7088540ccc
commit 1dee2c4200
9 changed files with 208 additions and 85 deletions
@@ -29,10 +29,15 @@ const Map = () => {
ruseUtztnFcltCd: fclt.pbnstRuseFcltId,
}));
if (!window.opener || typeof window.opener.postMessage !== "function") {
alert("부모 창을 찾을 수 없습니다. 팝업이 'noopener'로 열렸거나, 보안 정책으로 차단되었을 수 있어요.");
return;
}
window.opener.postMessage(
{
type: "SET_SUBS_INFO",
payload: subsInfoList, // 또는 필요한 데이터
payload: subsInfoList, // 배열로 전송 (최대 3개)
},
"*"
);
@@ -52,9 +57,23 @@ const Map = () => {
//하수처리시설코드로 재이용시설 목록 조회
const reuseData = async (ruseFcltPk: any) => {
if (!ruseFcltPk) {
console.warn("[reuseData] ruseFcltPk가 없습니다.");
return;
}
try {
console.log("[reuseData] API 호출 - ruseFcltPk:", ruseFcltPk);
const response = await mapService.getPbnstRuseFclts(ruseFcltPk);
const data = response.data || [];
console.log("[reuseData] API 응답 전체:", response);
// 응답이 배열이면 바로 사용, 객체면 .data 추출
const data = Array.isArray(response)
? response
: Array.isArray(response?.data)
? response.data
: response?.data
? [response.data]
: [];
console.log("[reuseData] 파싱된 data:", data);
setSelectedFclts((prev) => {
const newItems = data.filter(
(item: any) =>
@@ -62,7 +81,7 @@ const Map = () => {
Object.keys(item).length > 0 &&
!prev.some((f) => f.pbnstRuseFcltId === item.pbnstRuseFcltId)
);
console.log(newItems);
console.log("[reuseData] 추가될 newItems:", newItems);
return [...prev, ...newItems];
});
} catch (error) {
@@ -75,11 +94,45 @@ const Map = () => {
fetchData();
}, []);
// 부모창에 초기 선택값 요청 (팝업 열릴 때 기존 선택 목록 받아오기)
useEffect(() => {
const origin = window.location.origin;
if (window.opener) {
window.opener.postMessage({ type: "REQUEST_INIT_SUBS_INFO" }, origin);
}
}, []);
// 부모창에서 초기 선택값 수신
useEffect(() => {
const origin = window.location.origin;
const handler = (event: MessageEvent) => {
if (event.origin !== origin) return;
const data = event.data;
if (!data || typeof data !== "object") return;
if (data.type === "INIT_SUBS_INFO") {
const list = Array.isArray(data.payload) ? data.payload : [];
setSelectedFclts(
list.map((x) => ({
ruseUtztnFcltNm: x.ruseUtztnFcltNm ?? "",
pbnstRuseFcltId: x.ruseUtztnFcltCd ?? "",
}))
);
}
};
window.addEventListener("message", handler);
return () => window.removeEventListener("message", handler);
}, []);
// 레이어 생성 후 초기화 처리
const onCheckedLayersChange = () => {
//수요처 ID
const urlParams = new URLSearchParams(window.location.search);
const dmdInfoId = urlParams.get("dmdInfoId");
console.log("[하이라이트] dmdInfoId:", dmdInfoId);
//수요처 위치로 화면 이동
const maps = gisMaps.current;
@@ -88,22 +141,42 @@ const Map = () => {
const featureId = `${layerNm}.${dmdInfoId}`;
let foundFeature: any = null;
// 현재 로드된 레이어 목록 출력
const allLayerNames = maps
.getLayers()
.getArray()
.map((l: any) => l.get("lyrTyNm") || l.get("name") || "(unnamed)");
console.log("[하이라이트] 전체 레이어 목록:", allLayerNames);
console.log("[하이라이트] 탐색 대상 레이어:", layerNm);
console.log("[하이라이트] 탐색 대상 featureId:", featureId);
maps
.getLayers()
.getArray()
.forEach((layer: any) => {
if (layer.get("lyrTyNm") == layerNm) {
console.log("[하이라이트] 레이어 발견:", layerNm);
const source = layer.getSource?.();
if (source?.getFeatureById) {
const feature = source.getFeatureById(String(featureId).trim());
console.log("[하이라이트] feature 탐색결과:", feature);
if (feature) {
foundFeature = feature;
return;
}
}
// feature 못 찾을 때 소스 내 전체 feature ID 출력
if (source?.getFeatures) {
const allIds = source.getFeatures().map((f: any) => f.getId());
console.log("[하이라이트] 소스 내 전체 feature ID:", allIds);
}
}
}
});
if (!foundFeature) {
console.warn("[하이라이트] feature를 찾지 못했습니다. 위 레이어 목록/ID를 확인하세요.");
}
if (foundFeature) {
const geometry = foundFeature.getGeometry();
@@ -133,7 +206,7 @@ const Map = () => {
{ width: 30 }
);
} else {
alert("수요처의 좌표정보를 찾을수 없으므로, 상단 조회조건의 시설명을 입력하여 위치를 조회하시기 바랍니다.");
console.warn("수요처의 좌표정보를 찾을 수 없습니다. dmdInfoId:", dmdInfoId);
}
const formatNumber = (val: any) => {
@@ -185,6 +258,7 @@ const Map = () => {
// 검색해서 재이용시설 선택하면 해당 시설로 화면 이동 처리
useEffect(() => {
console.warn(selectDataPk);
if (!selectDataPk || Object.keys(selectDataPk).length === 0) return;
const maps = gisMaps.current;
let foundFeature: any = null;
@@ -226,8 +300,12 @@ const Map = () => {
// 재이용시설 클릭 시 선택 시설목록에 추가
const onFeatureSelect = (data: any) => {
// feature의 모든 속성 출력 (어떤 키가 있는지 확인)
const properties = data.getProperties?.() ?? {};
console.log("[onFeatureSelect] feature 속성 전체:", properties);
// 처리시설코드
const swtrmtFcltCd = data.get("swtrmt_fclt_cd");
console.log("[onFeatureSelect] swtrmt_fclt_cd:", swtrmtFcltCd);
reuseData(swtrmtFcltCd);
};
@@ -22,36 +22,32 @@ export default function SelectedFcltList({
const TableContent = (
<>
<thead className="bg-gray-100 text-gray-700 text-[13px]">
<thead className="bg-gray-100 text-gray-600 text-[11px] font-medium border-b border-cyan-800">
<tr>
<th className="px-3 py-2 text-left border-b">시설명</th>
<th className="px-3 py-2 text-right border-b">
하수처리량
<br />
(㎥/일)
<th className="px-2 py-1.5 text-left w-1/3">시설명</th>
<th className="px-2 py-1.5 text-right whitespace-nowrap">
처리량(㎥/일)
</th>
<th className="px-3 py-2 text-right border-b">
재이용량
<br />
(㎥/일)
<th className="px-2 py-1.5 text-right whitespace-nowrap">
재이용량(㎥/일)
</th>
<th className="px-3 py-2 border-b">삭제</th>
<th className="px-2 py-1.5 text-center w-10">삭제</th>
</tr>
</thead>
<tbody>
{data.map((item) => (
<tr key={item.pbnstRuseFcltId} className="border-b last:border-none">
<td className="px-3 py-2 text-[12px]">{item.ruseUtztnFcltNm}</td>
<td className="px-3 py-2 text-right text-[12px]">
<tr key={item.pbnstRuseFcltId} className="border-b border-gray-100 last:border-none hover:bg-gray-50/50">
<td className="px-2 py-1.5 text-[11px] font-medium text-gray-800 break-keep">{item.ruseUtztnFcltNm}</td>
<td className="px-2 py-1.5 text-right text-[11px] text-gray-600">
{Number(item.splyExtraCpct || 0).toLocaleString()}
</td>
<td className="px-3 py-2 text-right text-[12px]">
<td className="px-2 py-1.5 text-right text-[11px] text-gray-600">
{Number(item.ruseCpct || 0).toLocaleString()}
</td>
<td className="px-3 py-2 text-center">
<td className="px-2 py-1.5 text-center">
<button
onClick={() => handleDelete(item.pbnstRuseFcltId)}
className="text-red-500 hover:text-red-700 text-sm font-bold"
className="text-gray-400 hover:text-red-500 text-[11px] font-bold transition-colors"
aria-label="삭제"
title="삭제"
>
@@ -64,15 +60,13 @@ export default function SelectedFcltList({
</>
);
if (data.length === 0) return null;
return (
<div className="fixed right-40 top-[8rem] w-[40rem] max-h-[130rem] overflow-auto bg-white shadow-lg rounded p-4 border border-gray-300 z-50">
<h3 className="bg-cyan-700 text-white text-xl font-bold mb-2 p-2">
<div className="fixed right-20 top-[3.5rem] w-[22rem] max-h-[80vh] overflow-hidden bg-white/95 backdrop-blur-sm shadow-[0_4px_12px_rgba(0,0,0,0.1)] rounded-lg border border-gray-200 z-50 flex flex-col">
<h3 className="bg-cyan-700 text-white text-[13px] font-semibold p-2">
선택된 시설
</h3>
<div className="overflow-x-auto">
<table className="w-full text-sm text-gray-800 border border-gray-200">
<div className="overflow-y-auto w-full">
<table className="w-full text-sm text-gray-800 border-t border-gray-200 table-fixed">
{TableContent}
</table>
</div>
@@ -6,7 +6,7 @@ import { DEV_URL_WR, DEV_URL_SN } from "@/components/ui/config";
export type LyrStngProps = {
lyr_sn: string
lyr_nm: string
upper_lyr_sn: string
upper_lyr_sn: string
drawOrdr: string
flterSql: string
gobjTy: string
@@ -29,7 +29,7 @@ export type LyrStngProps = {
export const mapService = {
//레이어 설정 조회
getLyrStngs: async () => {
const response = await fetch(`${DEV_URL_SN}/api/v1/map/lyrStngs/DM_NETWORK`, {
const response = await fetch(`${DEV_URL_SN}/map/lyrStngs/DM_NETWORK`, {
method: 'GET',
headers: {
'Accept': 'application/json',
@@ -42,7 +42,7 @@ export const mapService = {
return response.json();
},
getPbnstRuseFclts: async (ruseFcltPk:any) => {
getPbnstRuseFclts: async (ruseFcltPk: any) => {
const response = await fetch(`${DEV_URL_WR}/reuseFc/pubFc/${ruseFcltPk}`, {
method: 'GET',
headers: {
@@ -9,6 +9,7 @@
"use client";
import { useMemo, useState, useRef, useEffect } from "react";
import { useRouter } from "next/navigation";
import SubPageHeader from "@/components/SubPageHeader";
import WaterQualityRefModal from "../modal/WaterQualityRefModal";
import CandidateSiteModal, { type CandidateSite } from "@/components/CandidateSiteModal";
@@ -19,6 +20,7 @@ import SimilarCaseModal, { type SimilarCaseDetail, type SimilarCaseRow } from "@
type PHRange = { min: string; max: string };
export default function DemandRegisterPage() {
const router = useRouter();
const today = useMemo(() => {
const d = new Date();
const yyyy = d.getFullYear();
@@ -63,6 +65,49 @@ export default function DemandRegisterPage() {
const getUseTypesData = useDmStore((state) => state.getUseTypesData);
const [openSimilar, setOpenSimilar] = useState(false);
// 후보지 팝업 메시지 핸들러
const candsRef = useRef<{ name: string; code: string }[]>([]);
useEffect(() => {
const origin = window.location.origin;
const handleMessage = (event: MessageEvent) => {
const data = event.data;
if (!data || typeof data !== "object") return;
if (data.type === "SET_SUBS_INFO") {
// 팝업에서 배열로 전송 (최대 3개)
const list = Array.isArray(data.payload) ? data.payload : [];
setCand1(list[0]?.ruseUtztnFcltNm ?? "");
setCand2(list[1]?.ruseUtztnFcltNm ?? "");
setCand3(list[2]?.ruseUtztnFcltNm ?? "");
// 추후 REQUEST_INIT_SUBS_INFO 응답용 ref 갱신
candsRef.current = list.map((x: any) => ({
name: x.ruseUtztnFcltNm ?? "",
code: x.ruseUtztnFcltCd ?? "",
}));
}
if (data.type === "REQUEST_INIT_SUBS_INFO") {
// 팝업이 현재 선택된 후보지 초기값을 요청하면 응답
const initList = candsRef.current
.filter((x) => x.name)
.map((x) => ({
ruseUtztnFcltNm: x.name,
ruseUtztnFcltCd: x.code,
}));
const target = event.source as Window | null;
target?.postMessage(
{ type: "INIT_SUBS_INFO", payload: initList },
{ targetOrigin: origin }
);
}
};
window.addEventListener("message", handleMessage);
return () => window.removeEventListener("message", handleMessage);
}, []);
// 유사사례
const similarCaseList = useDmStore((state) => state.Sdm.similarCaseList);
const getSimilarCaseList = useDmStore((state) => state.getSimilarCaseList);
@@ -208,6 +253,14 @@ export default function DemandRegisterPage() {
const user = userStr ? JSON.parse(userStr) : null;
if(user){
// 후보지 목록 (candsRef에 코드까지 보관됨)
const splyCndtList = candsRef.current
.filter((x) => x.name)
.map((x) => ({
ruseUtztnFcltNm: x.name,
ruseUtztnFcltCd: x.code,
}));
const payload : SdmInfoFormData = {
dmndTmng : new Date(reqDate),
dmdInfoId : user.dmdInfoId,
@@ -226,9 +279,13 @@ export default function DemandRegisterPage() {
smll : odor,
cdtnv : Number(ec)||null,
crmty : Number(color)||null,
rmrk : remark
rmrk : remark,
splyCndtList, // 후보지 목록 추가
}
const success = await insertSdmInfoData(payload);
if (success) {
router.push("/apply/status");
}
insertSdmInfoData(payload);
}
}
+7 -5
View File
@@ -1,4 +1,4 @@
import { fetchType, getFetch, postFetch, getFetchWithCount } from "@/components/ui/api";
import { fetchType, getFetch, postFetch, getFetchWithCount } from "@/components/ui/api";
import type { SelectDataType } from "@common/business_components/ui";
import type { TableUpperProps } from "../common";
import toast from "react-hot-toast";
@@ -454,13 +454,15 @@ const postSdmData = async (data: DemandCompType) => {
}
// 수요정보 등록
const postSdmInfoData = async (data: SdmInfoFormData) => {
const postSdmInfoData = async (data: SdmInfoFormData): Promise<boolean> => {
try {
await postFetch("/reuseFc/request/demandInfo", data);
alert('수요 정보 등록에 성공하였습니다.');
return true;
} catch (error) {
console.log(error);
alert('수요 정보 등록에 실패하였습니다.');
return false;
}
}
@@ -536,7 +538,7 @@ const fetchGetSimilarCaseList = async (part: string, value: number | string) =>
export type SdmActions = {
initializeSdmData: () => void;
insertSdmData: (data: DemandCompType) => Promise<void>;
insertSdmInfoData: (data: SdmInfoFormData) => Promise<void>;
insertSdmInfoData: (data: SdmInfoFormData) => Promise<boolean>;
getDemandCompList: (searchText: string, pageCnt: number) => Promise<void>;
actionLogin: (data: DemandCompType) => Promise<void>;
getSdmInfoStatusList: (dmdInfoId: string) => Promise<void>;
@@ -611,8 +613,8 @@ export const SdmReducer = (set: any): SdmActions => {
}
},
insertSdmInfoData: async (data: SdmInfoFormData) => {
postSdmInfoData(data);
insertSdmInfoData: async (data: SdmInfoFormData): Promise<boolean> => {
return await postSdmInfoData(data);
},
// 수요처 정보
+3 -3
View File
@@ -1,6 +1,6 @@
import { PROXY_HOST } from "@/src/shared/config/env";
export const LOCAL_URL = PROXY_HOST;
export const DEV_URL_FO = "/operation-service";
export const DEV_URL_WR = "/reuse-service";
export const DEV_URL_SN = "/sewerage-service";
export const DEV_URL_FO = "/operation-service/api/v1";
export const DEV_URL_WR = "/reuse-service/api/v1";
export const DEV_URL_SN = "/sewerage-service/api/v1";
@@ -94,7 +94,7 @@ export default function SearchInputText({
value={textValue || ""}
onChange={handleInputChange}
onKeyDown={handleKeyDown}
className="w-full h-[3.2rem] !text-xl pl-3 text-gray-600 border border-gray-300 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"
className="w-full h-8 text-xs pl-2 pr-2 text-gray-600 border border-gray-300 rounded focus:outline-none focus:ring-1 focus:ring-blue-500"
placeholder={`${label}을(를) 입력하세요`}
onClick={() => {
setTextValue("");
@@ -109,10 +109,10 @@ export default function SearchInputText({
searchList.map((item, index) => (
<div
key={index}
className={`w-full cursor-pointer overflow-auto px-5 py-3 text-left !text-xl ${
className={`w-full cursor-pointer px-3 py-2 text-left text-xs ${
highlightIndex === index
? "bg-blue-100"
: "hover:bg-gray-100"
? "bg-blue-50"
: "hover:bg-gray-50"
}`}
onClick={() => handleSuggestionClick(item.bscFctNm)}
role="button"
@@ -127,7 +127,7 @@ export default function SearchInputText({
</div>
))
) : (
<div className="!text-xl w-full px-5 py-3 hover:bg-gray-100 cursor-pointer overflow-auto">
<div className="text-xs w-full px-3 py-2 hover:bg-gray-50 cursor-pointer text-gray-500">
검색 결과가 없습니다.
</div>
)}
@@ -62,50 +62,51 @@ export function SearchBar({
);
return (
<div className="flex justify-center w-full px-4 py-3">
<div className="flex items-center w-full max-w-screen-lg rounded-xl bg-white shadow-md px-6 py-4 space-x-3">
<div className="flex justify-center w-full px-4 py-2">
<div className="flex items-center w-auto shadow-md px-4 py-2 space-x-2 bg-white/95 backdrop-blur-sm rounded-lg text-sm border border-gray-200">
<SelectBox
labelClass="w-[40px]"
className="w-[200px]"
labelClass="w-[50px] text-xs font-medium text-gray-700"
className="w-[110px]"
label="시도"
selectClass="rounded-lg bg-white"
selectClass="rounded bg-white text-xs h-8"
selectArray={Common.selectSidoData || []}
onSelectValue={(val) => onSelectValue(val.toString(), "ctpvCd")}
value={sidoValue || Common.selectSidoData[0]?.val || ""}
/>
<SelectBox
labelClass="w-[65px]"
className="w-[200px]"
labelClass="w-[70px] text-xs font-medium text-gray-700"
className="w-[110px]"
label="시군구"
selectClass="rounded-lg bg-white"
selectClass="rounded bg-white text-xs h-8"
selectArray={filteredSigunData || []}
onSelectValue={(val) => onSelectValue(val.toString(), "sggCd")}
value={sigunValue}
/>
<Label className="text-gray-600">하수재이용시설</Label>
<SearchInputText
label="시설명"
initValue={undefined}
setValue={(searchNm?: string) => {
let sggOrCity = "";
if (searchNm) {
if (sigunValue === "0" || sigunValue === "") {
sggOrCity = sidoValue;
} else {
sggOrCity = sigunValue;
<Label className="text-gray-700 text-xs font-medium pl-2 pr-1">하수재이용시설</Label>
<div className="w-[180px]">
<SearchInputText
label="시설명 입력"
initValue={undefined}
setValue={(searchNm?: string) => {
let sggOrCity = "";
if (searchNm) {
if (sigunValue === "0" || sigunValue === "") {
sggOrCity = sidoValue;
} else {
sggOrCity = sigunValue;
}
findRuseFclt(sggOrCity, searchNm);
}
findRuseFclt(sggOrCity, searchNm);
}
}}
setRtnData={(rtnData: any) => {
setHasuPk(rtnData);
}}
searchList={map.ruseFcltList || []}
/>
}}
setRtnData={(rtnData: any) => {
setHasuPk(rtnData);
}}
searchList={map.ruseFcltList || []}
/>
</div>
<Button
color="sky"
className="ml-2 text-white"
size="sm"
className="ml-2 text-white !h-8 !py-0 !px-3 !text-xs font-semibold rounded"
onClick={() => {
onApply();
}}
+1 -10
View File
@@ -28,15 +28,6 @@ export function middleware(req: NextRequest) {
console.log(`[Middleware] Request URL: ${req.url}`);
const searchParams = req.nextUrl.searchParams;
// if (pathname.startsWith("/server")) {
// const queryParams = searchParams.toString();
// const newUrl = `${serverApiUrl}${pathname.replace("/server", "")}${
// queryParams ? `?${queryParams}` : ""
// }`;
// console.log(`[Middleware] Rewriting from '/server' path to: ${newUrl}`);
// return NextResponse.rewrite(new URL(newUrl));
// }
if (pathname.startsWith("/server")) {
const decodedParams = Array.from(searchParams.entries())
.map(([key, value]) => `${key}=${decodeURIComponent(value)}`)
@@ -112,7 +103,7 @@ export function middleware(req: NextRequest) {
const url = req.nextUrl.clone();
url.searchParams.set("TYPENAME", typename.replace("hasudo:", ""));
queryParams = url.searchParams.toString();
newUrl = `${GATEWAY_URL}/api/v1/map/geometry${queryParams ? `?${queryParams}` : ""}`;
newUrl = `${GATEWAY_URL}/sewerage-service/api/v1/map/geometry${queryParams ? `?${queryParams}` : ""}`;
}
console.log(`[Middleware] Rewriting from '/geoserver' path to: ${newUrl}`);