Files
frontend/apps/wr/app/store/map/htdflMap/index.tsx
T
2025-08-13 13:17:31 +09:00

132 lines
3.8 KiB
TypeScript

import { fetchType, getFetch, getFetchWithCount } from "@/components/lib/api";
import type { CommonTableProps } from "../../common/type/header";
import type { customHtdflBdst } from "../../ruseFcltMng/fcltReg/htdflReg";
import { htdflSttHeadListExport, htdflSttNodeListExport } from "../../ruseFcltMng/fcltSttn/htdflSttn/headList";
import type { SelectDataType } from "@common/business_components/ui";
import { excelHtdflSttnParsing } from "../../ruseFcltMng/fcltSttn/htdflSttn/excel";
export const htdfMapSize = 15;
export type htdfMapState = {
htdfMap: {
htdfMapRes: customHtdflBdst[];
htdfMapCount: number;
htdflMapExcelList:[]
isInit: boolean;
htdfSttHeadList: CommonTableProps[];
htdfSttNodeList: CommonTableProps[];
};
};
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;
htdfMapDetile:(featureCd:string) => Promise<customHtdflBdst | undefined>;
};
export type htdfMapType = htdfMapState & htdfMapActions;
export const htdfMapStateExport: htdfMapState = {
htdfMap: {
isInit: false,
htdfMapRes: [],
htdflMapExcelList:[],
htdfMapCount: 1,
htdfSttHeadList: htdflSttHeadListExport,
htdfSttNodeList: htdflSttNodeListExport,
},
};
export const htdfMapActionsExport: (set: any) => htdfMapActions = (
set: any
) => {
return {
htdfMapInit: async (page: number, total: number, cityOrSgg: string) => {
try {
const htdfMapRes = await getFetchWithCount(
fetchType.WR,
`/drain/facilityList` +
(page ? `/${page}` : "/1") +
(total ? `/${total}` : "/20") +
(cityOrSgg ? `/${cityOrSgg}` : "/0")
);
set((state: htdfMapState) => {
return {
...state,
htdfMap: {
...state.htdfMap,
htdfMapRes: htdfMapRes.data,
htdfMapCount: htdfMapRes.count,
isInit: false,
},
};
});
} catch (e) {
console.log(e);
}
},
htdfMapSearch: async (isExcel: boolean, page: number, total: string, con: string, txt: string,
sidoCode: SelectDataType[],
sggCode: SelectDataType[]
) => {
try {
const htdfMapRes = await getFetchWithCount(
fetchType.WR,
`/drain/facilityList` +
(page ? `/${page}` : "/1") +
(total ? `/${total}` : "/20") +
(con ? `/${con}` : "/0") +
(txt ? `/${txt}` : "")
);
if (isExcel) {
const htdflMapExcelList = excelHtdflSttnParsing(htdfMapRes, sidoCode, sggCode);
set((state: htdfMapState) => {
return {
...state,
htdfMap: {
...state.htdfMap,
htdflMapExcelList: htdflMapExcelList
},
};
});
}else{
set((state: htdfMapState) => {
return {
...state,
htdfMap: {
...state.htdfMap,
htdfMapRes: htdfMapRes.data,
htdfMapCount: htdfMapRes.count,
},
};
});
}
} catch (e) {
console.log(e);
}
},
htdfMapDetile: async (featureCd: string) => {
try {
const htdfDetail = await getFetch(
fetchType.WR,
`/drain/facilityList/1/3/0/${featureCd}`
);
if (htdfDetail && htdfDetail.length > 0) {
return htdfDetail[0];
} else {
return null;
}
} catch (error) {
console.log(error);
throw error; // 호출부에서 catch 가능하도록
}
},
};
};