Files
frontend/apps/wr/app/store/map/pbnstMap/index.tsx
T

129 lines
3.7 KiB
TypeScript

import { fetchType, postFectch } 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";
export const pbnMapTableSize = 20;
const hasuListFetch = async (
page: number,
pageTotal: number,
reurnValue: ReturnType,
searchNm?: string
) => {
let url = `/prcsFclt/ruseInfo/${page}/${pageTotal}/`;
const checkWrRegListRes = await checkWrRegList();
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) => {
return {
...item,
fctCpc: Number(item.fctCpc) || 0,
ruse: item.ruse === false ? "N" : "Y",
};
});
return { data: hasuList, count: rainRes.count };
};
export type pbnMapState = {
pbnMap: {
isInit: boolean;
pbnMapRes: pubHasuType[];
pbnMapCount: number;
pbnMapHeadList: TableUpperProps[];
};
};
type pbnMapActions = {
pbnMapInit: (page: number, pageTotal: number, reurnValue: ReturnType) => void;
pbnMapDetaile: (featureCd: string, data: string) => Promise<pubHasuType | undefined>;
};
export type pbnMapType = pbnMapState & pbnMapActions;
export const pbnMapStateExport: pbnMapState = {
pbnMap: {
isInit: false,
pbnMapRes: [],
pbnMapCount: 1,
pbnMapHeadList: pubFacHeadListExport,
},
};
export const pbnMapActionsExport: (set: any) => pbnMapActions = (set: any) => {
return {
pbnMapInit: async (
page: number,
pageTotal: number,
reurnValue: ReturnType
) => {
try {
const pubMapRes = await hasuListFetch(page, pageTotal, reurnValue);
set((state: pbnMapState) => {
return {
...state,
pbnMap: {
...state.pbnMap,
pbnMapRes: pubMapRes.data,
pbnMapCount: pubMapRes.count,
isInit: false,
},
};
});
} catch (e) {
console.log(e);
}
},
pbnMapDetaile: async (featureCd: string, data: string) => {
try {
const hasuRes = await postFectch(
`/prcsFclt/ruseInfo/1/20/A/0/0/1/SW/${featureCd}`,
[data],
fetchType.COMMON
);
const filteredData = hasuRes.data.map((item: any) => {
return {
...item,
fctCpc: Number(item.fctCpc) || 0,
ruse: item.ruse === false ? "N" : "Y",
};
});
return filteredData;
} catch (error) {
console.log(error);
throw error; // 호출부에서 catch 가능하도록
}
},
};
};