204 lines
5.5 KiB
TypeScript
204 lines
5.5 KiB
TypeScript
import { getFetchWithCount } from "@/components/lib/api";
|
|
import type { pubHasuType } from "../../ruseFcltMng/fcltReg/pbnstReg/type";
|
|
import type { ReturnType} from "@common/business_components/ui";
|
|
import { pubFacHeadListExport } from "../../ruseFcltMng/fcltReg/pbnstReg/headList";
|
|
import type { TableUpperProps } from "../../common/type/header";
|
|
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,
|
|
page: number,
|
|
pageTotal: number,
|
|
reurnValue: ReturnType,
|
|
searchNm?: string
|
|
) => {
|
|
const url = buildPbnstRegListUrl(page, pageTotal, reurnValue, searchNm);
|
|
const response = await getFetchWithCount("wr", url);
|
|
|
|
const hasuList = response.data.map((item: any) => {
|
|
return {
|
|
...item,
|
|
fctCpc: Number(item.fctCpc) || 0,
|
|
ruse: item?.ruse ?? "N",
|
|
rswtrYn: item?.rswtrYn ?? "N",
|
|
};
|
|
});
|
|
|
|
return { data: hasuList, count: response.count };
|
|
};
|
|
|
|
export type pbnMapState = {
|
|
pbnMap: {
|
|
isInit: boolean;
|
|
pbnMapRes: pubHasuType[];
|
|
pbnMapCount: number;
|
|
pbnMapHeadList: TableUpperProps[];
|
|
hasuMapExcelList:[]
|
|
};
|
|
};
|
|
|
|
type pbnMapActions = {
|
|
pbnMapInit: (page: number, pageTotal: number, reurnValue: ReturnType) => void;
|
|
pbnMapSearch: (
|
|
isExcel: boolean,
|
|
page: number,
|
|
pageTotal: number,
|
|
reurnValue: ReturnType,
|
|
txt: string,
|
|
) => Promise<string[][] | undefined>;
|
|
pbnMapDetaile: (
|
|
featureCd: string,
|
|
) => Promise<pubHasuType | undefined>;
|
|
};
|
|
|
|
export type pbnMapType = pbnMapState & pbnMapActions;
|
|
|
|
export const pbnMapStateExport: pbnMapState = {
|
|
pbnMap: {
|
|
isInit: false,
|
|
pbnMapRes: [],
|
|
pbnMapCount: 1,
|
|
pbnMapHeadList: pubFacHeadListExport,
|
|
hasuMapExcelList:[]
|
|
},
|
|
};
|
|
|
|
export const pbnMapActionsExport: (set: any, get: any) => pbnMapActions = (set: any, get: any) => {
|
|
return {
|
|
pbnMapInit: async (
|
|
page: number,
|
|
pageTotal: number,
|
|
reurnValue: ReturnType
|
|
) => {
|
|
try {
|
|
const pubMapRes = await hasuListFetch(get, set, 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) => {
|
|
try {
|
|
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 ?? "N",
|
|
rswtrYn: item?.rswtrYn ?? "N",
|
|
};
|
|
});
|
|
return filteredData[0];
|
|
} catch (error) {
|
|
console.log(error);
|
|
throw error; // 호출부에서 catch 가능하도록
|
|
}
|
|
},
|
|
pbnMapSearch: async (
|
|
isExcel: boolean,
|
|
page: number,
|
|
pageTotal: number,
|
|
reurnValue: ReturnType,
|
|
txt: string,
|
|
) => {
|
|
try {
|
|
const hasuMapRes = await hasuListFetch(get, set, page, pageTotal, reurnValue, txt);
|
|
if (isExcel) {
|
|
const hasuMapExcelList = excelHasuMapParsing(
|
|
hasuMapRes
|
|
);
|
|
set((state: pbnMapState) => {
|
|
return {
|
|
...state,
|
|
pbnMap: {
|
|
...state.pbnMap,
|
|
hasuMapExcelList: hasuMapExcelList
|
|
},
|
|
};
|
|
});
|
|
return hasuMapExcelList;
|
|
} else {
|
|
set((state: pbnMapState) => {
|
|
return {
|
|
...state,
|
|
pbnMap: {
|
|
...state.pbnMap,
|
|
pbnMapRes: hasuMapRes.data,
|
|
pbnMapCount: hasuMapRes.count,
|
|
isInit: false,
|
|
},
|
|
};
|
|
});
|
|
}
|
|
} catch (e) {
|
|
console.log(e);
|
|
}
|
|
return undefined;
|
|
},
|
|
};
|
|
};
|