wr: 하수재이용실적 등록1
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/**
|
||||
/**
|
||||
* 재이용실적등록 > 하수재이용실적등록
|
||||
*/
|
||||
"use client";
|
||||
@@ -10,13 +10,11 @@ import {
|
||||
initValOutUsage,
|
||||
subTotalObj,
|
||||
totalObj,
|
||||
type FcPrfType,
|
||||
type PbnstPrfRegDtlType,
|
||||
type PbnstPrfRegListType,
|
||||
type PrfType,
|
||||
} from "@/app/store/prfmncReg/pbnstPrfmncReg/type";
|
||||
import {
|
||||
excelDownload,
|
||||
yearOptions,
|
||||
} from "@/components/lib/func/common";
|
||||
import { excelDownload, yearOptions } from "@/components/lib/func/common";
|
||||
import { useConfirm } from "@frontend-opensource/use-react-hooks";
|
||||
import { pbnstTableBody } from "@/components/lib/func/TableData";
|
||||
import PbnPrfExcelModal from "@/components/ui/modal/chkgd/pbnPrfExcelModal/pbnPrfExcelModal";
|
||||
@@ -32,18 +30,104 @@ import {
|
||||
UiTable,
|
||||
} from "@common/business_components/ui";
|
||||
import ListDiv from "@common/business_components/ui/list_div";
|
||||
import {
|
||||
Button,
|
||||
Label,
|
||||
Table,
|
||||
TableBody,
|
||||
TableHeader,
|
||||
} from "@common/components/ui";
|
||||
import { useCallback, useEffect, useRef, useState } from "react";
|
||||
import { Button, Label, Table, TableBody, TableHeader } from "@common/components/ui";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useAlertStore } from "@/src/shared/lib";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { headMakeprfmnc } from "../chkgdnReg/TableHead";
|
||||
|
||||
type PbnstPrfmncRow = {
|
||||
sido: string;
|
||||
gugun: string;
|
||||
bscFctNm: string;
|
||||
ruseUtztnFcltNm: string;
|
||||
pbnstRuseFcltId: string;
|
||||
};
|
||||
|
||||
const buildInputData = (detail: PbnstPrfRegDtlType | null, searchYear: string) => {
|
||||
if (!detail?.prfList?.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const inUsageData = structuredClone(initValInUsage).map((row) => ({
|
||||
...row,
|
||||
구분: "장내용수",
|
||||
}));
|
||||
const outUsageData = structuredClone(initValOutUsage).map((row) => ({
|
||||
...row,
|
||||
구분: "장외용수",
|
||||
}));
|
||||
const inSubtotal = {
|
||||
...structuredClone(subTotalObj),
|
||||
구분: "장내용수",
|
||||
};
|
||||
const outSubtotal = {
|
||||
...structuredClone(subTotalObj),
|
||||
구분: "장외용수",
|
||||
};
|
||||
|
||||
detail.prfList.forEach((prfItem) => {
|
||||
const yr = Number(prfItem.ym?.slice(0, 4));
|
||||
if (yr !== Number(searchYear)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const month = Number(prfItem?.ym?.slice(4));
|
||||
const monthKey = `${month}월`;
|
||||
|
||||
inUsageData.forEach((inData: any) => {
|
||||
const usageKey = inData.usage;
|
||||
const value = (prfItem as any)[usageKey] ?? 0;
|
||||
|
||||
inData[monthKey] = value;
|
||||
inData.total += value;
|
||||
|
||||
if (usageKey !== "subtotal") {
|
||||
(inSubtotal as any)[monthKey] =
|
||||
((inSubtotal as any)[monthKey] ?? 0) + value;
|
||||
inSubtotal.total += value;
|
||||
}
|
||||
});
|
||||
|
||||
outUsageData.forEach((outData: any) => {
|
||||
const usageKey = outData.usage;
|
||||
const value = (prfItem as any)[usageKey] ?? 0;
|
||||
|
||||
outData[monthKey] = value;
|
||||
outData.total += value;
|
||||
|
||||
if (usageKey !== "subtotal") {
|
||||
(outSubtotal as any)[monthKey] =
|
||||
((outSubtotal as any)[monthKey] ?? 0) + value;
|
||||
outSubtotal.total += value;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (inSubtotal.total === 0 && outSubtotal.total === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
inUsageData.push(inSubtotal);
|
||||
outUsageData.push(outSubtotal);
|
||||
|
||||
const usageTotalObj: { [key: string]: any } = {
|
||||
...structuredClone(totalObj),
|
||||
구분: "총합계",
|
||||
용수명: "",
|
||||
};
|
||||
for (const key in usageTotalObj) {
|
||||
if (["usage", "gubun", "edit"].includes(key)) continue;
|
||||
const val =
|
||||
(Number((inSubtotal as any)[key]) || 0) +
|
||||
(Number((outSubtotal as any)[key]) || 0);
|
||||
|
||||
(usageTotalObj as any)[key] = val;
|
||||
}
|
||||
|
||||
return [...inUsageData, ...outUsageData, usageTotalObj];
|
||||
};
|
||||
|
||||
export default function PrfmncPrfmncReg() {
|
||||
const {
|
||||
auth,
|
||||
@@ -51,59 +135,85 @@ export default function PrfmncPrfmncReg() {
|
||||
prfmncHasuInit,
|
||||
prfmnRegData,
|
||||
prfmncHasuNmSearch,
|
||||
getPrfFmcRes,
|
||||
getPbnstPrfRegDtl,
|
||||
getLaeSeCdCheck,
|
||||
returnCodeText,
|
||||
} = useWrStore((state) => state);
|
||||
const {
|
||||
prfPbnFclts,
|
||||
pbnstPrfmncHeadList,
|
||||
monthHeadList,
|
||||
prfmncRes,
|
||||
prfmncResCount,
|
||||
} = prfmnc;
|
||||
const { pbnstPrfmncHeadList, monthHeadList, prfmncRes, prfmncResCount, prfmncDetail } =
|
||||
prfmnc;
|
||||
const { regAuthrtYn, mdfcnAuthrtYn, laeSeCd } = auth;
|
||||
const [isReset, setIsReset] = useState(false);
|
||||
const [bdstTable, setbdstTable] = useState<FcPrfType[]>();
|
||||
const [searchTxt, setSearchTxt] = useState<string>();
|
||||
const [searchTxt, setSearchTxt] = useState<string>("");
|
||||
const [selectedFacilityId, setSelectedFacilityId] = useState<string>("");
|
||||
const [selectedIndex, setSelectedIndex] = useState<number>(0);
|
||||
const [inputData, setInputData] = useState<any[]>([]);
|
||||
const [isExcelOpen, setIsExcelOPen] = useState<{
|
||||
isModal: boolean;
|
||||
data: FcPrfType;
|
||||
}>({ isModal: false, data: {} as FcPrfType });
|
||||
const [inputData, setInputData] = useState<any[]>();
|
||||
const [pbnstRuseFcltId, setpbnstRuseFcltId] = useState<string>();
|
||||
const [cellNum, setCellNum] = useState<number>(1);
|
||||
const [searchYear, setSearchYear] = useState<string>(
|
||||
String(new Date().getFullYear())
|
||||
);
|
||||
data: PbnstPrfRegDtlType;
|
||||
}>({ isModal: false, data: {} as PbnstPrfRegDtlType });
|
||||
const [searchYear, setSearchYear] = useState<string>(String(new Date().getFullYear()));
|
||||
const { confirm } = useConfirm();
|
||||
const alert = useAlertStore((state) => state.setMessage);
|
||||
const { t } = useTranslation("base");
|
||||
|
||||
const useInitRef = useRef(false);
|
||||
const bdstTable = useMemo<PbnstPrfmncRow[]>(
|
||||
() =>
|
||||
prfmncRes.map((item: PbnstPrfRegListType) => ({
|
||||
sido: returnCodeText(item.sidoCd, "cityCd"),
|
||||
gugun:
|
||||
item.sggCd && String(item.sggCd).trim().length === 5
|
||||
? returnCodeText(String(item.sggCd), "sggCd")
|
||||
: "",
|
||||
bscFctNm: item.swageBscFctNm,
|
||||
ruseUtztnFcltNm: item.ruseUtztnFcltNm,
|
||||
pbnstRuseFcltId: item.pbnstRuseFcltId,
|
||||
})),
|
||||
[prfmncRes, returnCodeText]
|
||||
);
|
||||
|
||||
const derivedInputData = useMemo(
|
||||
() => buildInputData(prfmncDetail, searchYear),
|
||||
[prfmncDetail, searchYear]
|
||||
);
|
||||
|
||||
const excelClick = useCallback(() => {
|
||||
excelDownload(
|
||||
[[]],
|
||||
"하수재이용실적",
|
||||
"sample_pbnstPrfmncReg.xlsx",
|
||||
"A1:O1"
|
||||
);
|
||||
}, [prfmnc.excelList]);
|
||||
excelDownload([[]], "하수재이용실적", "sample_pbnstPrfmncReg.xlsx", "A1:O1");
|
||||
}, []);
|
||||
|
||||
const loadDetail = useCallback(
|
||||
async (facilityId: string) => {
|
||||
if (!facilityId) return;
|
||||
|
||||
const detail = await getPbnstPrfRegDtl(searchYear, facilityId);
|
||||
if (detail) {
|
||||
setSelectedFacilityId(facilityId);
|
||||
setIsExcelOPen((prev) => ({
|
||||
...prev,
|
||||
data: detail,
|
||||
}));
|
||||
}
|
||||
},
|
||||
[getPbnstPrfRegDtl, searchYear]
|
||||
);
|
||||
|
||||
const handleSearch = useCallback(() => {
|
||||
if (!laeSeCd) return;
|
||||
|
||||
setIsReset(true);
|
||||
}, [laeSeCd]);
|
||||
|
||||
const { t } = useTranslation("base");
|
||||
const onSave = useCallback(async () => {
|
||||
const handleConfirm = async () => {
|
||||
if (!pbnstRuseFcltId) return;
|
||||
if (!selectedFacilityId) return;
|
||||
|
||||
const message = await prfmnRegData(
|
||||
1,
|
||||
laeSeCd,
|
||||
excelToPbnPrfData(
|
||||
inputData as unknown as JSON[],
|
||||
searchYear,
|
||||
pbnstRuseFcltId
|
||||
) as unknown as PrfType,
|
||||
selectedFacilityId
|
||||
) as unknown as PrfType[],
|
||||
searchYear,
|
||||
prfPbnFclts
|
||||
selectedFacilityId
|
||||
);
|
||||
alert(message);
|
||||
};
|
||||
@@ -111,126 +221,47 @@ export default function PrfmncPrfmncReg() {
|
||||
if (await confirm(t("isUpdateMsg"))) {
|
||||
await handleConfirm();
|
||||
}
|
||||
}, [inputData, searchYear, pbnstRuseFcltId, cellNum, prfPbnFclts, confirm, t, laeSeCd, prfmnRegData]);
|
||||
|
||||
const cellClick = useCallback(
|
||||
(index: number | undefined) => {
|
||||
if (index !== undefined) {
|
||||
setIsExcelOPen({
|
||||
isModal: false,
|
||||
data: prfmncRes[index] || ({} as FcPrfType),
|
||||
});
|
||||
const inUsageData = structuredClone(initValInUsage).map((row) => ({
|
||||
...row,
|
||||
구분: "장내용수",
|
||||
}));
|
||||
const outUsageData = structuredClone(initValOutUsage).map((row) => ({
|
||||
...row,
|
||||
구분: "장외용수",
|
||||
}));
|
||||
const inSubtotal = {
|
||||
...structuredClone(subTotalObj),
|
||||
구분: "장내용수",
|
||||
};
|
||||
const outSubtotal = {
|
||||
...structuredClone(subTotalObj),
|
||||
구분: "장외용수",
|
||||
};
|
||||
if (prfmncRes[index]?.prfList) {
|
||||
prfmncRes[index].prfList?.forEach((prfItem) => {
|
||||
const yr = Number(prfItem.ym?.slice(0, 4)); // "YYYY"
|
||||
|
||||
if (yr === Number(searchYear)) {
|
||||
const month = Number(prfItem?.ym?.slice(4)); // "MM"
|
||||
const monthKey = `${month}월`;
|
||||
|
||||
inUsageData.forEach((inData: any) => {
|
||||
const usageKey = inData.usage;
|
||||
const value = (prfItem as any)[usageKey] ?? 0;
|
||||
|
||||
inData[monthKey] = value;
|
||||
inData.total += value;
|
||||
|
||||
if (inSubtotal && usageKey !== "subtotal") {
|
||||
(inSubtotal as any)[monthKey] =
|
||||
((inSubtotal as any)[monthKey] ?? 0) + value;
|
||||
inSubtotal.total += value;
|
||||
}
|
||||
});
|
||||
|
||||
outUsageData.forEach((outData: any) => {
|
||||
const usageKey = outData.usage;
|
||||
const value = (prfItem as any)[usageKey] ?? 0;
|
||||
|
||||
outData[monthKey] = value;
|
||||
outData.total += value;
|
||||
|
||||
if (usageKey !== "subtotal") {
|
||||
(outSubtotal as any)[monthKey] =
|
||||
((outSubtotal as any)[monthKey] ?? 0) + value;
|
||||
outSubtotal.total += value;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
if (inSubtotal.total !== 0 && outSubtotal.total !== 0) {
|
||||
inUsageData.push(inSubtotal);
|
||||
outUsageData.push(outSubtotal);
|
||||
const usageTotalObj: { [key: string]: any } = {
|
||||
...structuredClone(totalObj),
|
||||
구분: "총합계",
|
||||
용수명: "",
|
||||
};
|
||||
for (const key in usageTotalObj) {
|
||||
if (["usage", "gubun", "edit"].includes(key)) continue;
|
||||
const val =
|
||||
(Number((inSubtotal as any)[key]) || 0) +
|
||||
(Number((outSubtotal as any)[key]) || 0);
|
||||
|
||||
(usageTotalObj as any)[key] = val;
|
||||
}
|
||||
const tableData = [...inUsageData, ...outUsageData, usageTotalObj];
|
||||
setpbnstRuseFcltId(prfmncRes[index].pbnstRuseFcltId);
|
||||
setInputData(tableData);
|
||||
} else {
|
||||
setInputData([]);
|
||||
}
|
||||
} else {
|
||||
setInputData([]);
|
||||
}
|
||||
}
|
||||
},
|
||||
[prfmncRes, searchYear]
|
||||
);
|
||||
useEffect(() => {
|
||||
getLaeSeCdCheck();
|
||||
useInitRef.current = true;
|
||||
}, []);
|
||||
useEffect(() => {
|
||||
if (useInitRef.current == true && laeSeCd !== undefined) {
|
||||
getPrfFmcRes();
|
||||
useInitRef.current = true;
|
||||
}
|
||||
}, [useInitRef.current, laeSeCd]);
|
||||
}, [alert, confirm, inputData, prfmnRegData, searchYear, selectedFacilityId, t]);
|
||||
|
||||
useEffect(() => {
|
||||
const year = new Date().getFullYear();
|
||||
|
||||
if(laeSeCd === undefined || laeSeCd ==='') return;
|
||||
prfmncHasuInit(1, laeSeCd, String(year), prfPbnFclts);
|
||||
}, [prfPbnFclts,laeSeCd]);
|
||||
void getLaeSeCdCheck();
|
||||
}, [getLaeSeCdCheck]);
|
||||
|
||||
useEffect(() => {
|
||||
if (prfmncRes && prfmncRes.length > 0) {
|
||||
setbdstTable(prfmncRes);
|
||||
if (!laeSeCd) return;
|
||||
void prfmncHasuInit(1, laeSeCd);
|
||||
}, [laeSeCd, prfmncHasuInit]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!prfmncRes.length) {
|
||||
setSelectedFacilityId("");
|
||||
setSelectedIndex(0);
|
||||
setInputData([]);
|
||||
setIsExcelOPen((prev) => ({ ...prev, data: {} as PbnstPrfRegDtlType }));
|
||||
return;
|
||||
}
|
||||
|
||||
// cellNum이 0일 경우(첫 번째 행)도 유효한 인덱스이므로 undefined 여부만 체크합니다.
|
||||
if (cellNum !== undefined) {
|
||||
cellClick(cellNum);
|
||||
const nextIndex = Math.max(
|
||||
prfmncRes.findIndex((item) => item.pbnstRuseFcltId === selectedFacilityId),
|
||||
0
|
||||
);
|
||||
const nextFacility = prfmncRes[nextIndex];
|
||||
if (!nextFacility) {
|
||||
return;
|
||||
}
|
||||
}, [prfmncRes, cellNum, cellClick]);
|
||||
|
||||
setSelectedIndex(nextIndex);
|
||||
void loadDetail(nextFacility.pbnstRuseFcltId);
|
||||
}, [loadDetail, prfmncRes]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!selectedFacilityId) return;
|
||||
void loadDetail(selectedFacilityId);
|
||||
}, [loadDetail, searchYear, selectedFacilityId]);
|
||||
|
||||
useEffect(() => {
|
||||
setInputData(derivedInputData);
|
||||
}, [derivedInputData]);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -249,9 +280,7 @@ export default function PrfmncPrfmncReg() {
|
||||
selectClass={""}
|
||||
selectArray={yearOptions}
|
||||
value={searchYear}
|
||||
onSelectValue={(val: string | number) =>
|
||||
setSearchYear(String(val))
|
||||
}
|
||||
onSelectValue={(val: string | number) => setSearchYear(String(val))}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-span-3 flex flex-row space-x-2">
|
||||
@@ -261,7 +290,7 @@ export default function PrfmncPrfmncReg() {
|
||||
<SearchInput
|
||||
className={"w-full text-2xl"}
|
||||
label=""
|
||||
textValue={searchTxt || ""}
|
||||
textValue={searchTxt}
|
||||
setText={(e) => {
|
||||
setSearchTxt(e);
|
||||
}}
|
||||
@@ -271,12 +300,7 @@ export default function PrfmncPrfmncReg() {
|
||||
<SearchFormRight className="w-3/12 mx-5 flex flex-col items-center justify-center space-x-2 ">
|
||||
<div className="space-y">
|
||||
<div className="flex flex-row space-x-2">
|
||||
<Button
|
||||
className={btnClass}
|
||||
onClick={() => {
|
||||
setIsReset(true);
|
||||
}}
|
||||
>
|
||||
<Button className={btnClass} onClick={handleSearch}>
|
||||
조회
|
||||
</Button>
|
||||
<Button
|
||||
@@ -291,12 +315,11 @@ export default function PrfmncPrfmncReg() {
|
||||
<Button
|
||||
className={btnClass}
|
||||
onClick={() => {
|
||||
if (cellNum === undefined) {
|
||||
if (!selectedFacilityId) {
|
||||
alert("하수처리재이용시설을 선택해주세요.");
|
||||
return;
|
||||
} else {
|
||||
setIsExcelOPen({ ...isExcelOpen, isModal: true });
|
||||
}
|
||||
setIsExcelOPen((prev) => ({ ...prev, isModal: true }));
|
||||
}}
|
||||
disabled={regAuthrtYn === "N"}
|
||||
>
|
||||
@@ -318,30 +341,29 @@ export default function PrfmncPrfmncReg() {
|
||||
<ScrollArea className="h-[60vh]">
|
||||
<UiTable
|
||||
key={"leftTable"}
|
||||
tableData={bdstTable || []}
|
||||
tableData={bdstTable}
|
||||
headlist={pbnstPrfmncHeadList}
|
||||
pageSize={10}
|
||||
total={prfmncResCount}
|
||||
headName={"하수재이용시설 목록"}
|
||||
cellClick={(index: number | undefined) => {
|
||||
cellClick(index);
|
||||
setCellNum(index ?? 0);
|
||||
if (index === undefined) return;
|
||||
const selected = prfmncRes[index];
|
||||
if (!selected) return;
|
||||
|
||||
setSelectedIndex(index);
|
||||
void loadDetail(selected.pbnstRuseFcltId);
|
||||
}}
|
||||
onPageChange={(page: number) => {
|
||||
if (searchTxt && searchTxt?.length > 0) {
|
||||
prfmncHasuNmSearch(
|
||||
page,
|
||||
laeSeCd,
|
||||
searchYear,
|
||||
searchTxt,
|
||||
prfPbnFclts
|
||||
);
|
||||
if (searchTxt.trim().length > 0) {
|
||||
void prfmncHasuNmSearch(page, laeSeCd, searchTxt);
|
||||
} else {
|
||||
prfmncHasuInit(page, laeSeCd, searchYear, prfPbnFclts);
|
||||
void prfmncHasuInit(page, laeSeCd);
|
||||
}
|
||||
setIsReset(false);
|
||||
}}
|
||||
resetPageNo={isReset}
|
||||
index={selectedIndex}
|
||||
/>
|
||||
</ScrollArea>
|
||||
</ListDiv>
|
||||
@@ -353,19 +375,21 @@ export default function PrfmncPrfmncReg() {
|
||||
{"하수처리수재이용 실적(m³) 등록결과"}
|
||||
</h3>
|
||||
</div>
|
||||
<Table variant="secondary">
|
||||
<TableHeader className="font-bold">
|
||||
{headMakeprfmnc(monthHeadList, [])}
|
||||
</TableHeader>
|
||||
<TableBody key={prfmnc.pageKey + "pageKey"}>
|
||||
{pbnstTableBody(
|
||||
inputData ?? [],
|
||||
monthHeadList,
|
||||
setInputData,
|
||||
mdfcnAuthrtYn === "N" ? false : true
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
<div className="card !m-[1.2rem]">
|
||||
<Table variant="secondary">
|
||||
<TableHeader className="font-bold">
|
||||
{headMakeprfmnc(monthHeadList, [])}
|
||||
</TableHeader>
|
||||
<TableBody key={prfmnc.pageKey + "pageKey"}>
|
||||
{pbnstTableBody(
|
||||
inputData,
|
||||
monthHeadList,
|
||||
setInputData,
|
||||
mdfcnAuthrtYn === "N" ? false : true
|
||||
)}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</div>
|
||||
</ScrollArea>
|
||||
</ListDiv>
|
||||
</div>
|
||||
@@ -376,22 +400,20 @@ export default function PrfmncPrfmncReg() {
|
||||
<PbnPrfExcelModal
|
||||
data={isExcelOpen.data}
|
||||
setIsExcelOPen={(open) => {
|
||||
setIsExcelOPen({ ...isExcelOpen, isModal: open });
|
||||
setIsExcelOPen((prev) => ({ ...prev, isModal: open }));
|
||||
}}
|
||||
setModalExcelData={async (excelData) => {
|
||||
const message = await prfmnRegData(1, laeSeCd, excelData, searchYear, prfPbnFclts);
|
||||
if (!selectedFacilityId) return;
|
||||
const message = await prfmnRegData(excelData, searchYear, selectedFacilityId);
|
||||
alert(message);
|
||||
// 데이터 저장 후 UI 업데이트는 useEffect가 감지하여 처리하므로 여기서는 호출하지 않습니다.
|
||||
}}
|
||||
></PbnPrfExcelModal>
|
||||
}
|
||||
open={isExcelOpen.isModal}
|
||||
onOpenChange={() => {
|
||||
setIsExcelOPen({ ...isExcelOpen, isModal: false });
|
||||
setIsExcelOPen((prev) => ({ ...prev, isModal: false }));
|
||||
}}
|
||||
></UiModal>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,229 +1,155 @@
|
||||
/**
|
||||
/**
|
||||
* 재이용실적등록 > 하수재이용실적등록
|
||||
*
|
||||
* 🔗 사용 API
|
||||
* - 하수재이용시설 실적 조회: POST /api/v1/reuseFc/pubDetailList/{year}/{sggOrCity}/{page}/{pageSize} (reuse-service)
|
||||
* - 하수재이용시설 실적 등록: POST /api/v1/reuseFc/pubFcPrf (reuse-service)
|
||||
* - 공공재이용시설 목록 조회: POST /api/v1/prcsFclt/ruseInfo/{page}/{pageSize}/{type}/{sggOrCity}/{etc1}/{etc2}/{etc3} (server-service)
|
||||
* - 공공재이용시설 목록 조회(이름검색): POST /api/v1/prcsFclt/ruseInfo/{page}/{pageSize}/{type}/{sggOrCity}/{searchTxt} (server-service)
|
||||
* - 공공재이용시설 조회: GET /api/v1/reuseFc/pubFc (reuse-service)
|
||||
*
|
||||
* 🔗 사용 API
|
||||
* - 좌측 목록 조회: GET /api/v1/reuseFc/pbnstPrfRegList/{page}/{pageSize}/{searchingCd}/{nameCd}
|
||||
* - 우측 상세 조회: GET /api/v1/reuseFc/pbnstPrfRegDtl/{year}/{pbnstRuseFcltId}
|
||||
* - 하수재이용시설 실적 등록: POST /api/v1/reuseFc/pubFcPrf
|
||||
**/
|
||||
import { fetchType, getFetch, postFectch } from "@/components/lib/api";
|
||||
import { fetchType, getFetch, getFetchWithCount, postFectch } from "@/components/lib/api";
|
||||
import { pbnstPrfmncHeadListExport, monthHeadListExport } from "./headList";
|
||||
import type { pubHasuType } from "../../ruseFcltMng/fcltReg/pbnstReg/type";
|
||||
import type { FcPrfType, PrfType } from "./type";
|
||||
import type { PbnstPrfRegDtlType, PbnstPrfRegListType, PrfType } from "./type";
|
||||
import type { TableUpperProps } from "../../common/type/header";
|
||||
|
||||
const pbnstPrfmncHeadList = pbnstPrfmncHeadListExport;
|
||||
const monthHeadList = monthHeadListExport;
|
||||
export const prfRegPageSize = 10;
|
||||
|
||||
export type pbnstPrfmncState = {
|
||||
prfmnc: {
|
||||
isInit: boolean;
|
||||
pbnstPrfmncHeadList: TableUpperProps[];
|
||||
monthHeadList: TableUpperProps[];
|
||||
prfmncRes: FcPrfType[];
|
||||
prfmncRes: PbnstPrfRegListType[];
|
||||
prfmncResCount: number;
|
||||
excelList: number[];
|
||||
pageKey: number;
|
||||
prfPbnFclts: string[];
|
||||
prfmncDetail: PbnstPrfRegDtlType | null;
|
||||
};
|
||||
};
|
||||
|
||||
export const pbnstPrfmncStateExport: pbnstPrfmncState = {
|
||||
prfmnc: {
|
||||
isInit: false,
|
||||
pbnstPrfmncHeadList: pbnstPrfmncHeadList,
|
||||
monthHeadList: monthHeadList,
|
||||
pbnstPrfmncHeadList,
|
||||
monthHeadList,
|
||||
prfmncRes: [],
|
||||
prfPbnFclts: [],
|
||||
prfmncResCount: 1,
|
||||
excelList: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
pageKey: 1,
|
||||
prfmncDetail: null,
|
||||
},
|
||||
};
|
||||
|
||||
export type pbnstPrfmncType = pbnstPrfmncState & pbnstPrfmncActions;
|
||||
|
||||
type pbnstPrfmncActions = {
|
||||
prfmncHasuInit: (
|
||||
page: number,
|
||||
sggOrCity: string,
|
||||
year: string,
|
||||
prfPbnFclts: string[]
|
||||
) => void;
|
||||
prfmncHasuNmSearch: (
|
||||
page: number,
|
||||
sggOrCity: string,
|
||||
year: string,
|
||||
searchTxt: string,
|
||||
prfPbnFclts: string[]
|
||||
) => void;
|
||||
prfmnRegData: (
|
||||
page: number,
|
||||
sggOrCity: string,
|
||||
data: PrfType,
|
||||
year: string,
|
||||
prfPbnFclts: string[]
|
||||
) => Promise<string>;
|
||||
getPrfFmcRes: () => void;
|
||||
prfmncHasuInit: (page: number, sggOrCity: string) => void;
|
||||
prfmncHasuNmSearch: (page: number, sggOrCity: string, searchTxt: string) => void;
|
||||
prfmnRegData: (data: PrfType[], year: string, pbnstRuseFcltId: string) => Promise<string>;
|
||||
getPbnstPrfRegDtl: (year: string, pbnstRuseFcltId: string) => Promise<PbnstPrfRegDtlType | undefined>;
|
||||
};
|
||||
|
||||
const hasuListFetch = async (
|
||||
const fetchPbnstPrfRegList = async (
|
||||
page: number,
|
||||
sggOrCity: string,
|
||||
year: string,
|
||||
prfPbnFclts: string[],
|
||||
searchTxt?: string
|
||||
) => {
|
||||
let filteredFclt = prfPbnFclts;
|
||||
if (sggOrCity !== "0") {
|
||||
filteredFclt = prfPbnFclts?.filter((fclt: string) => {
|
||||
return sggOrCity.length == 2
|
||||
? fclt.slice(0, 2) === sggOrCity
|
||||
: fclt.slice(0, 5) === sggOrCity;
|
||||
});
|
||||
let url = `/reuseFc/pbnstPrfRegList/${page}/${prfRegPageSize}/A/${sggOrCity}`;
|
||||
if (searchTxt && searchTxt.trim().length > 0) {
|
||||
url += `?swtrmtFcltNm=${encodeURIComponent(searchTxt.trim())}`;
|
||||
}
|
||||
//let url = `/prcsFclt/ruseInfo/1/${filteredFclt.length + 1}/A/${sggOrCity}/0/1/SW`;
|
||||
let url = `/prcsFclt/ruseInfo/1/${filteredFclt.length + 1}`;
|
||||
if (searchTxt && searchTxt?.length > 0) {
|
||||
url += `/${searchTxt}`;
|
||||
}
|
||||
const rainRes = await postFectch(url, filteredFclt, fetchType.COMMON);
|
||||
|
||||
const checkRuseFcltList =
|
||||
searchTxt && searchTxt?.length > 0
|
||||
? rainRes.data.map((item) => item.bscFctCd)
|
||||
: filteredFclt;
|
||||
|
||||
const pubRuseList = await postFectch(
|
||||
`/reuseFc/pubDetailList/${year}/${sggOrCity}/${page}/${prfRegPageSize}`,
|
||||
checkRuseFcltList,
|
||||
fetchType.WR
|
||||
);
|
||||
const rusePrfList = pubRuseList.data
|
||||
.map((item: FcPrfType) => {
|
||||
const findData = rainRes.data?.find(
|
||||
(fclt: pubHasuType) =>
|
||||
item.pbnstRuseFcltId.substring(0, 11) === fclt?.bscFctCd
|
||||
);
|
||||
if (findData !== undefined) {
|
||||
return {
|
||||
sido: findData.sido,
|
||||
gugun: findData.gugun,
|
||||
bscFctNm: findData.bscFctNm,
|
||||
bscFctCd: findData.bscFctCd,
|
||||
ruseUtztnFcltNm: item.ruseUtztnFcltNm,
|
||||
pbnstRuseFcltId: item.pbnstRuseFcltId,
|
||||
prfList: item.prfList,
|
||||
};
|
||||
}
|
||||
})
|
||||
.filter(Boolean); // undefined 값을 제거합니다.
|
||||
|
||||
return { data: rusePrfList, count: pubRuseList.count };
|
||||
const response = await getFetchWithCount(fetchType.WR, url);
|
||||
return {
|
||||
data: (response?.data ?? []) as PbnstPrfRegListType[],
|
||||
count: response?.count ?? 0,
|
||||
};
|
||||
};
|
||||
|
||||
export const pbnstPrfmncActionsExport: (set: any) => pbnstPrfmncActions = (
|
||||
set: any
|
||||
) => {
|
||||
return {
|
||||
getPrfFmcRes: async () => {
|
||||
prfmncHasuInit: async (page: number, sggOrCity: string) => {
|
||||
try {
|
||||
const pbnPrfRes = await getFetch(fetchType.WR, "/reuseFc/pubFc");
|
||||
set((state: pbnstPrfmncState) => ({
|
||||
const prfmncRes = await fetchPbnstPrfRegList(page, sggOrCity);
|
||||
return set((state: pbnstPrfmncState) => ({
|
||||
...state,
|
||||
prfmnc: {
|
||||
...state.prfmnc,
|
||||
prfPbnFclts: pbnPrfRes,
|
||||
prfmncRes: prfmncRes.data,
|
||||
prfmncResCount: prfmncRes.count,
|
||||
prfmncDetail: null,
|
||||
isInit: false,
|
||||
},
|
||||
}));
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
},
|
||||
prfmncHasuInit: async (
|
||||
page: number,
|
||||
sggOrCity: string,
|
||||
year: string,
|
||||
prfPbnFclts: string[]
|
||||
) => {
|
||||
try {
|
||||
const prfmncRes = await hasuListFetch(
|
||||
page,
|
||||
sggOrCity,
|
||||
year,
|
||||
prfPbnFclts
|
||||
);
|
||||
return set((state: pbnstPrfmncState) => ({
|
||||
...state,
|
||||
prfmnc: {
|
||||
...state.prfmnc,
|
||||
prfmncRes: prfmncRes.data,
|
||||
prfmncResCount: prfmncRes.count,
|
||||
isInit: false,
|
||||
},
|
||||
}));
|
||||
} catch (errorHasu) {
|
||||
console.log(errorHasu);
|
||||
}
|
||||
},
|
||||
prfmncHasuNmSearch: async (
|
||||
page: number,
|
||||
sggOrCity: string,
|
||||
year: string,
|
||||
searchTxt: string,
|
||||
prfPbnFclts: string[]
|
||||
searchTxt: string
|
||||
) => {
|
||||
try {
|
||||
const prfmncRes = await hasuListFetch(
|
||||
page,
|
||||
sggOrCity,
|
||||
year,
|
||||
prfPbnFclts,
|
||||
searchTxt
|
||||
);
|
||||
const prfmncRes = await fetchPbnstPrfRegList(page, sggOrCity, searchTxt);
|
||||
return set((state: pbnstPrfmncState) => ({
|
||||
...state,
|
||||
prfmnc: {
|
||||
...state.prfmnc,
|
||||
prfmncRes: prfmncRes.data,
|
||||
prfmncResCount: prfmncRes.count,
|
||||
prfmncDetail: null,
|
||||
isInit: false,
|
||||
},
|
||||
}));
|
||||
} catch (errorHasu) {
|
||||
console.log(errorHasu);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
},
|
||||
prfmnRegData: async (
|
||||
page: number,
|
||||
sggOrCity: string,
|
||||
data: PrfType,
|
||||
year: string,
|
||||
prfPbnFclts: string[]
|
||||
) => {
|
||||
getPbnstPrfRegDtl: async (year: string, pbnstRuseFcltId: string) => {
|
||||
try {
|
||||
const detail = (await getFetch(
|
||||
fetchType.WR,
|
||||
`/reuseFc/pbnstPrfRegDtl/${year}/${pbnstRuseFcltId}`
|
||||
)) as PbnstPrfRegDtlType;
|
||||
|
||||
set((state: pbnstPrfmncState) => ({
|
||||
...state,
|
||||
prfmnc: {
|
||||
...state.prfmnc,
|
||||
prfmncDetail: detail,
|
||||
},
|
||||
}));
|
||||
|
||||
return detail;
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
return undefined;
|
||||
}
|
||||
},
|
||||
prfmnRegData: async (data: PrfType[], year: string, pbnstRuseFcltId: string) => {
|
||||
const failMessage = "하수재이용 시설 실적 등록이 실패하였습니다.";
|
||||
try {
|
||||
const ressponse = await postFectch(
|
||||
const response = await postFectch(
|
||||
"/reuseFc/pubFcPrf",
|
||||
data,
|
||||
fetchType.WR
|
||||
);
|
||||
|
||||
if (ressponse.status === 200) {
|
||||
const prfmncRes = await hasuListFetch(
|
||||
page,
|
||||
sggOrCity,
|
||||
year,
|
||||
prfPbnFclts
|
||||
);
|
||||
if (response.status === 200) {
|
||||
const detail = (await getFetch(
|
||||
fetchType.WR,
|
||||
`/reuseFc/pbnstPrfRegDtl/${year}/${pbnstRuseFcltId}`
|
||||
)) as PbnstPrfRegDtlType;
|
||||
|
||||
set((state: pbnstPrfmncState) => ({
|
||||
...state,
|
||||
prfmnc: {
|
||||
...state.prfmnc,
|
||||
prfmncRes: prfmncRes.data,
|
||||
prfmncResCount: prfmncRes.count,
|
||||
prfmncDetail: detail,
|
||||
isInit: false,
|
||||
pageKey: state.prfmnc.pageKey + 1,
|
||||
},
|
||||
|
||||
@@ -54,8 +54,26 @@ export const FcPrfSchema = z.object({
|
||||
bscFctNm: z.string().nullish(),
|
||||
});
|
||||
|
||||
export const PbnstPrfRegListSchema = z.object({
|
||||
swageBscFctNm: z.string().default(""),
|
||||
ruseUtztnFcltNm: z.string().default(""),
|
||||
pbnstRuseFcltId: z.string().default(""),
|
||||
sidoCd: z.string().default(""),
|
||||
sggCd: z.string().default(""),
|
||||
totalCount: z.number().default(0),
|
||||
});
|
||||
|
||||
export const PbnstPrfRegDtlSchema = z.object({
|
||||
pbnstRuseFcltId: z.string().default(""),
|
||||
ruseUtztnFcltNm: z.string().default(""),
|
||||
swageBscFctNm: z.string().default(""),
|
||||
prfList: z.array(PrfSchema).default([]),
|
||||
});
|
||||
|
||||
export type FcPrfType = z.infer<typeof FcPrfSchema>;
|
||||
export type PrfType = z.infer<typeof PrfSchema>;
|
||||
export type PbnstPrfRegListType = z.infer<typeof PbnstPrfRegListSchema>;
|
||||
export type PbnstPrfRegDtlType = z.infer<typeof PbnstPrfRegDtlSchema>;
|
||||
|
||||
export const initValInUsage:PrfUsageSummary[] = [
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user