diff --git a/apps/wr/app/store/map/htdflMap/index.tsx b/apps/wr/app/store/map/htdflMap/index.tsx index a8b9eb7c1..7815bfa79 100644 --- a/apps/wr/app/store/map/htdflMap/index.tsx +++ b/apps/wr/app/store/map/htdflMap/index.tsx @@ -21,7 +21,7 @@ type htdfMapActions = { htdfMapInit: (page: number, total: number, cityOrSgg: string) => void; htdfMapSearch: (isExcel: boolean, page: number, total: string, con: string, txt: string, sidoCode: SelectDataType[], - sggCode: SelectDataType[]) => void; + sggCode: SelectDataType[]) => Promise; htdfMapDetile:(featureCd:string) => Promise; }; @@ -93,6 +93,7 @@ export const htdfMapActionsExport: (set: any) => htdfMapActions = ( }, }; }); + return htdflMapExcelList; }else{ set((state: htdfMapState) => { @@ -109,6 +110,7 @@ export const htdfMapActionsExport: (set: any) => htdfMapActions = ( } catch (e) { console.log(e); } + return undefined; }, htdfMapDetile: async (featureCd: string) => { try { diff --git a/apps/wr/app/store/map/pbnstMap/index.tsx b/apps/wr/app/store/map/pbnstMap/index.tsx index 80eb2697a..f7a81a3a9 100644 --- a/apps/wr/app/store/map/pbnstMap/index.tsx +++ b/apps/wr/app/store/map/pbnstMap/index.tsx @@ -1,6 +1,5 @@ -import { fetchType, postFectch } from "@/components/lib/api"; +import { getFetchWithCount } from "@/components/lib/api"; import type { pubHasuType } from "../../ruseFcltMng/fcltReg/pbnstReg/type"; -import { checkWrRegList } from "../../ruseFcltMng/fcltReg/pbnstReg"; import type { ReturnType} from "@common/business_components/ui"; import { pubFacHeadListExport } from "../../ruseFcltMng/fcltReg/pbnstReg/headList"; import type { TableUpperProps } from "../../common/type/header"; @@ -8,54 +7,68 @@ import { excelHasuMapParsing } from "./excel"; export const pbnMapTableSize = 20; +const buildPbnstRegListUrl = ( + page: number, + pageTotal: number, + reurnValue: ReturnType, + searchNm?: string, + featureCd?: string +) => { + let searchingCd = "A"; + let nameCd = "0"; + + if (reurnValue.partValue === "A") { + searchingCd = "A"; + nameCd = + reurnValue.sigunValue !== "0" ? reurnValue.sigunValue : reurnValue.sidoValue; + } else if (reurnValue.partValue === "R") { + searchingCd = "R"; + nameCd = reurnValue.regionValue + ? reurnValue.regionValue + : reurnValue.unitWaterShedValue + ? reurnValue.unitWaterShedValue + : reurnValue.middleRegionValue; + } else if (reurnValue.partValue === "G") { + searchingCd = reurnValue.envPartValue; + nameCd = + reurnValue.sigunValue !== "0" ? reurnValue.sigunValue : reurnValue.sidoValue; + } + + const url = `/reuseFc/pbnstRegList/${page}/${pageTotal}/${searchingCd}/${nameCd || "0"}/0/1/SW`; + const queryParams = new URLSearchParams(); + + if (searchNm && searchNm.length > 0) { + queryParams.set("swtrmtFcltNm", searchNm); + } + if (featureCd) { + queryParams.set("bscFctCd", featureCd); + } + + const queryString = queryParams.toString(); + return queryString ? `${url}?${queryString}` : url; +}; + const hasuListFetch = async ( - get: any, - set: any, + _get: any, + _set: any, page: number, pageTotal: number, reurnValue: ReturnType, searchNm?: string ) => { - let url = `/prcsFclt/ruseInfo/${page}/${pageTotal}/`; - const checkWrRegListRes = await checkWrRegList(get, set); + const url = buildPbnstRegListUrl(page, pageTotal, reurnValue, searchNm); + const response = await getFetchWithCount("wr", url); - if (reurnValue.partValue === "A") { - url += `${reurnValue.partValue}/${ - // reurnValue.sidoValue ? reurnValue.sidoValue : reurnValue.sigunValue - reurnValue.sigunValue !== "0" - ? reurnValue.sigunValue - : reurnValue.sidoValue - }/0/1/SW`; - } else if (reurnValue.partValue === "R") { - url += `${reurnValue.partValue}/${ - reurnValue.regionValue - ? reurnValue.regionValue - : reurnValue.unitWaterShedValue - ? reurnValue.unitWaterShedValue - : reurnValue.middleRegionValue - }/0/1/SW`; - } else if (reurnValue.partValue === "G") { - url += `${reurnValue.envPartValue}/${reurnValue.sigunValue !== "0" ? reurnValue.sigunValue : reurnValue.sidoValue}/0/1/SW`; - } else { - url += `A/0/0/1/SW`; - } - if (searchNm && searchNm?.length > 0) { - url += "/" + searchNm; - } - - const data = checkWrRegListRes.filter((item: string) => item !== ""); - - const rainRes = await postFectch(url, data, fetchType.COMMON); - - const hasuList = rainRes.data.map((item: any) => { + const hasuList = response.data.map((item: any) => { return { ...item, fctCpc: Number(item.fctCpc) || 0, - ruse: item.ruse === false ? "N" : "Y", + ruse: item?.ruse ?? "N", + rswtrYn: item?.rswtrYn ?? "N", }; }); - return { data: hasuList, count: rainRes.count }; + return { data: hasuList, count: response.count }; }; export type pbnMapState = { @@ -76,7 +89,7 @@ type pbnMapActions = { pageTotal: number, reurnValue: ReturnType, txt: string, - ) => void; + ) => Promise; pbnMapDetaile: ( featureCd: string, ) => Promise; @@ -120,16 +133,23 @@ export const pbnMapActionsExport: (set: any, get: any) => pbnMapActions = (set: }, pbnMapDetaile: async ( featureCd: string) => { try { - const hasuRes = await postFectch( - `/prcsFclt/ruseInfo/1/1/A/0/0/1/SW/`, - [featureCd], - fetchType.COMMON - ); + const defaultReturnType = { + partValue: "A", + sidoValue: "0", + sigunValue: "0", + regionValue: "0", + unitWaterShedValue: "0", + middleRegionValue: "0", + envPartValue: "0", + } as ReturnType; + const url = buildPbnstRegListUrl(1, 1, defaultReturnType, undefined, featureCd); + const hasuRes = await getFetchWithCount("wr", url); const filteredData = hasuRes.data.map((item: any) => { return { ...item, fctCpc: Number(item.fctCpc) || 0, - ruse: item.ruse === false ? "N" : "Y", + ruse: item?.ruse ?? "N", + rswtrYn: item?.rswtrYn ?? "N", }; }); return filteredData[0]; @@ -160,6 +180,7 @@ export const pbnMapActionsExport: (set: any, get: any) => pbnMapActions = (set: }, }; }); + return hasuMapExcelList; } else { set((state: pbnMapState) => { return { @@ -176,6 +197,7 @@ export const pbnMapActionsExport: (set: any, get: any) => pbnMapActions = (set: } catch (e) { console.log(e); } + return undefined; }, }; }; diff --git a/apps/wr/app/store/map/rainMap/index.tsx b/apps/wr/app/store/map/rainMap/index.tsx index 050639096..1dba165bd 100644 --- a/apps/wr/app/store/map/rainMap/index.tsx +++ b/apps/wr/app/store/map/rainMap/index.tsx @@ -23,7 +23,7 @@ export type rainMapState = { type rainMapActions = { rainMapInit: (page: number, total: number, cityOrSgg:string) => void; - rainMapSearch: (isExcel: boolean, page: number, total: string, con: string, txt: string,code:Record) => void; + rainMapSearch: (isExcel: boolean, page: number, total: string, con: string, txt: string,code:Record) => Promise; rainMapDetile:(featureCd:string) => Promise; }; @@ -92,6 +92,7 @@ export const rainMapActionsExport: (set: any) => rainMapActions = ( }, }; }); + return rainMapExcelList; }else{ set((state: rainMapState) => { return { @@ -108,6 +109,7 @@ export const rainMapActionsExport: (set: any) => rainMapActions = ( } catch (e) { console.log(e); } + return undefined; }, rainMapDetile: async (featureCd: string) => { try { diff --git a/apps/wr/app/store/map/rswtMap/index.tsx b/apps/wr/app/store/map/rswtMap/index.tsx index 1c98a4dd2..94bd1d2c4 100644 --- a/apps/wr/app/store/map/rswtMap/index.tsx +++ b/apps/wr/app/store/map/rswtMap/index.tsx @@ -24,7 +24,7 @@ type rswtMapActions = { rswtMapInit: (page: number, total: number, cityOrSgg: string) => void; rswtMapSearch: ( isExcel: boolean, page: number, total: string, con: string, txt: string, code:Record - ) => void; + ) => Promise; rswtMapDetile: (featureCd: string) => Promise; }; @@ -92,6 +92,7 @@ export const rswtMapActionsExport: (set: any) => rswtMapActions = ( }, }; }); + return rswtMapExcelList; }else{ set((state: rswtMapState) => { @@ -108,6 +109,7 @@ export const rswtMapActionsExport: (set: any) => rswtMapActions = ( } catch (e) { console.log(e); } + return undefined; }, rswtMapDetile: async (featureCd: string) => { try { diff --git a/apps/wr/components/ui/map/LayerPopUp/HasuFacilty/HasuFacility.tsx b/apps/wr/components/ui/map/LayerPopUp/HasuFacilty/HasuFacility.tsx index 5a622b2c6..a3b686bfb 100644 --- a/apps/wr/components/ui/map/LayerPopUp/HasuFacilty/HasuFacility.tsx +++ b/apps/wr/components/ui/map/LayerPopUp/HasuFacilty/HasuFacility.tsx @@ -25,7 +25,7 @@ export function HasuFacility({rtnFeature}:{rtnFeature:(feature:any)=>void } ) { const [isReset, setIsReset] = useState(false); const [pbnRuseNm, setPbnRuseNm] = useState(""); const ref = useRef({} as ReturnType); - const { pbnMapHeadList, pbnMapRes, pbnMapCount ,hasuMapExcelList} = pbnMap; + const { pbnMapHeadList, pbnMapRes, pbnMapCount } = pbnMap; const { t } = useTranslation("base"); useEffect(() => { @@ -46,21 +46,6 @@ export function HasuFacility({rtnFeature}:{rtnFeature:(feature:any)=>void } ) { } }; - - useEffect(() => { - if (hasuMapExcelList.length > 0) { - excelDownload( - hasuMapExcelList, - "하수처리시설 현황", - "sample_hasuMap.xlsx", - "A1:H1", - 2 - ); - } else { - toast.error(t("excelDownErrMsg")); - } - }, [hasuMapExcelList]); - return ( <> @@ -103,12 +88,28 @@ export function HasuFacility({rtnFeature}:{rtnFeature:(feature:any)=>void } ) { btnClass={btnClass} ref={ref} isAdmin={false} - excelClick={function (returnType: ReturnType): void { + excelClick={async function (returnType: ReturnType): Promise { console.log("pbnstSttnSearch ", returnType); + const excelList = await pbnMapSearch( + true, + 1, + 100000, + returnType, + pbnRuseNm ?? "" + ); + if (excelList && excelList.length > 0) { + excelDownload( + excelList, + "하수처리시설 현황", + "sample_hasuMap.xlsx", + "A1:H1", + 2 + ); + return; + } - pbnMapSearch(true,1, 100000, returnType,pbnRuseNm??'' ) - + toast.error(t("excelDownErrMsg")); }} /> diff --git a/apps/wr/components/ui/map/LayerPopUp/HedfFacilty/HtdfFacilty.tsx b/apps/wr/components/ui/map/LayerPopUp/HedfFacilty/HtdfFacilty.tsx index 86da242d7..3b72f21e5 100644 --- a/apps/wr/components/ui/map/LayerPopUp/HedfFacilty/HtdfFacilty.tsx +++ b/apps/wr/components/ui/map/LayerPopUp/HedfFacilty/HtdfFacilty.tsx @@ -40,7 +40,6 @@ export function HtdflFacility({ const { htdfMapCount, - htdflMapExcelList, htdfMapRes, htdfSttHeadList, htdfSttNodeList, @@ -105,19 +104,6 @@ export function HtdflFacility({ setHtdflTable(chData); }, [code, htdfMapRes]); - useEffect(() => { - if (htdflMapExcelList.length > 0) { - excelDownload( - htdflMapExcelList, - "온배수시설 현황", - "sample_htdflSttn.xlsx", - "A1:R3" - ); - } else { - toast.error(t("excelDownErrMsg")); - } - }, [htdflMapExcelList]); - return ( <> @@ -166,13 +152,13 @@ export function HtdflFacility({ className="mt-2" size={"sm"} color="green" - onClick={() => { + onClick={async () => { const con = objSearch.sgg && objSearch.sgg !== "0" ? objSearch.sgg : objSearch.city; if (con) { - htdfMapSearch( + const excelList = await htdfMapSearch( true, 1, "1000000", @@ -181,6 +167,16 @@ export function HtdflFacility({ code.cityCd, code.sggCd ); + if (excelList && excelList.length > 0) { + excelDownload( + excelList, + "온배수시설 현황", + "sample_htdflSttn.xlsx", + "A1:R3" + ); + return; + } + toast.error(t("excelDownErrMsg")); } }} > diff --git a/apps/wr/components/ui/map/LayerPopUp/RainFacility/RainFacility.tsx b/apps/wr/components/ui/map/LayerPopUp/RainFacility/RainFacility.tsx index 74bf0aa55..154b8dadc 100644 --- a/apps/wr/components/ui/map/LayerPopUp/RainFacility/RainFacility.tsx +++ b/apps/wr/components/ui/map/LayerPopUp/RainFacility/RainFacility.tsx @@ -31,7 +31,7 @@ export function RainFacility({ const { code, rainMap, rainMapInit, rainMapSearch } = useWrStore( (state) => state ); - const { rainMapRes, rainMapExcelList,rainMapCount, rainSttHeadList, rainSttNodeList } = + const { rainMapRes, rainMapCount, rainSttHeadList, rainSttNodeList } = rainMap; const [rainTable, setRainTable] = useState(); const [isReset, setIsReset] = useState(false); @@ -122,18 +122,6 @@ export function RainFacility({ .filter((item: any) => item.rainyObj !== undefined); setRainTable(chData); }, [code, rainMapRes]); - useEffect(() => { - if (rainMapExcelList.length > 0) { - excelDownload( - rainMapExcelList, - "빗물이용시설 현황", - "sample_rainSttn.xlsx", - "A1:W3" - ); - } else { - toast.error(t("excelDownErrMsg")); - } - }, [rainMapExcelList]); return ( <> @@ -182,13 +170,13 @@ export function RainFacility({ className="mt-2" size={"sm"} color="green" - onClick={() => { + onClick={async () => { const con = objSearch.sgg && objSearch.sgg !== "0" ? objSearch.sgg : objSearch.city; if (con) { - rainMapSearch( + const excelList = await rainMapSearch( true, 1, "1000000", @@ -196,6 +184,16 @@ export function RainFacility({ seartchTxt ?? "", code as unknown as Record ); + if (excelList && excelList.length > 0) { + excelDownload( + excelList, + "빗물이용시설 현황", + "sample_rainSttn.xlsx", + "A1:W3" + ); + return; + } + toast.error(t("excelDownErrMsg")); } }} > diff --git a/apps/wr/components/ui/map/LayerPopUp/RswtFacilty/RswtFacilty.tsx b/apps/wr/components/ui/map/LayerPopUp/RswtFacilty/RswtFacilty.tsx index 4fe818568..b7f8e6bed 100644 --- a/apps/wr/components/ui/map/LayerPopUp/RswtFacilty/RswtFacilty.tsx +++ b/apps/wr/components/ui/map/LayerPopUp/RswtFacilty/RswtFacilty.tsx @@ -31,7 +31,7 @@ export function RswtFacility({ const { code, rswtMap, rswtMapInit, rswtMapSearch } = useWrStore( (state) => state ); - const { rswtMapRes, rswtMapExcelList, rswtMapCount, rswtSttHeadList, rswtSttNodeList } = + const { rswtMapRes, rswtMapCount, rswtSttHeadList, rswtSttNodeList } = rswtMap; const [rswtrTable, setRswtrTable] = useState(); const [isReset, setIsReset] = useState(false); @@ -118,18 +118,6 @@ export function RswtFacility({ setRswtrTable(chData); }, [code, rswtMapRes]); - useEffect(() => { - if (rswtMapExcelList.length > 0) { - excelDownload( - rswtMapExcelList, - "중수도시설 현황", - "sample_rswtSttn.xlsx", - "A1:W3", - ); - } else { - toast.error(t('excelDownErrMsg')); - } - }, [rswtMapExcelList]); return ( <> @@ -178,13 +166,13 @@ export function RswtFacility({ className="mt-2" size={"sm"} color="green" - onClick={() => { + onClick={async () => { const con = objSearch.sgg && objSearch.sgg !== "0" ? objSearch.sgg : objSearch.city; if (con) { - rswtMapSearch( + const excelList = await rswtMapSearch( true, 1, "1000000", @@ -192,6 +180,16 @@ export function RswtFacility({ seartchTxt ?? "", code as unknown as Record ); + if (excelList && excelList.length > 0) { + excelDownload( + excelList, + "중수도시설 현황", + "sample_rswtSttn.xlsx", + "A1:W3", + ); + return; + } + toast.error(t('excelDownErrMsg')); } }} >